RestService
AuthenticationMode
Bases: Enum
ACCESS_TOKEN = 9
class-attribute
instance-attribute
BASIC = 1
class-attribute
instance-attribute
BASIC_API_KEY = 8
class-attribute
instance-attribute
CAM = 3
class-attribute
instance-attribute
CAM_SSO = 4
class-attribute
instance-attribute
IBM_CLOUD_API_KEY = 5
class-attribute
instance-attribute
PA_PROXY = 7
class-attribute
instance-attribute
SERVICE_TO_SERVICE = 6
class-attribute
instance-attribute
WIA = 2
class-attribute
instance-attribute
use_v12_auth
property
BytesIOSocket(content)
used in urllib3_response_from_bytes method to construct urllib3 response from raw bytes
Source code in TM1py/Services/RestService.py
RestService(**kwargs)
Low level communication with TM1 instance through HTTP. Allows to execute HTTP Methods - GET - POST - PATCH - DELETE Takes Care of - Encodings - TM1 User-Login - HTTP Headers - HTTP Session Management - Response Handling Based on requests module
Create an instance of RESTService
Supported kwargs arguments:
- address (str): Address of the TM1 instance.
- port (int): HTTPPortNumber as specified in the tm1s.cfg.
- ssl (bool): Use SSL as specified in the tm1s.cfg.
- instance (str): Planning Analytics Engine (v12) instance name.
- database (str): Planning Analytics Engine (v12) database name.
- base_url (str): Base URL.
- auth_url (str): Auth URL for Planning Analytics Engine (v12).
- user (str): Name of the user.
- password (str): Password of the user.
- decode_b64 (bool): Whether password argument is b64 encoded.
- namespace (str): Optional CAM namespace.
- cam_passport (str): The CAM passport.
- session_id (str): TM1SessionId, e.g. q7O6e1w49AixeuLVxJ1GZg.
- application_client_id (str): Planning Analytics Engine (v12) named application client ID created via manage service.
- application_client_secret (str): Planning Analytics Engine (v12) named application secret created via manage service.
- api_key (str): Planning Analytics Engine (v12) API Key from https://cloud.ibm.com/iam/apikeys.
- iam_url (str): Planning Analytics Engine (v12) IBM Cloud IAM URL. Default: "https://iam.cloud.ibm.com".
- pa_url (str): Planning Analytics Engine (v12) PA URL, e.g., "https://us-east-2.aws.planninganalytics.ibm.com".
- cpd_url (str): Cloud Pack for Data URL (aka ZEN) CPD URL, e.g., "https://cpd-zen.apps.cp4dpa-test11.cp.fyre.ibm.com".
- tenant (str): Planning Analytics Engine (v12) Tenant, e.g., YC4B2M1AG2Y6.
- session_context (str): Name of the Application. Controls "Context" column in Arc / TM1top. If None, uses default: TM1py.
- verify (str|bool): Path to .cer file or 'True' / True / 'False' / False (if no SSL verification is required).
- logging (bool): Switch on/off verbose HTTP logging into sys.stdout.
- timeout (float): Number of seconds that the client will wait to receive the first byte.
- cancel_at_timeout (bool): Abort operation in TM1 when timeout is reached.
- async_requests_mode (bool): Changes internal REST execution mode to avoid 60s timeout on IBM cloud.
- connection_pool_size (int): Maximum number of connections to save in the pool (default: 10). In a multi-threaded environment, set higher.
- pool_connections (int): Number of connection pools to cache (default: 1 for a single TM1 instance).
- integrated_login (bool): True for IntegratedSecurityMode3.
- integrated_login_domain (str): NT Domain name. Default: '.' for local account.
- integrated_login_service (str): Kerberos Service type for remote Service Principal Name. Default: 'HTTP'.
- integrated_login_host (str): Host name for Service Principal Name. Default: Extracted from request URI.
- integrated_login_delegate (bool): Indicates that the user's credentials are to be delegated to the server. Default: False.
- impersonate (str): Name of user to impersonate.
- re_connect_on_session_timeout (bool): Attempt to reconnect once if session is timed out.
- re_connect_on_remote_disconnect (bool): Attempt to reconnect once if connection is aborted by remote end.
- remote_disconnect_max_retries (int): Maximum number of retry attempts after remote disconnect (default: 5).
- remote_disconnect_retry_delay (float): Initial delay in seconds before first retry attempt (default: 1).
- remote_disconnect_max_delay (float): Maximum delay cap in seconds between retry attempts (default: 30).
- remote_disconnect_backoff_factor (float): Multiplier for exponential backoff between retry attempts (default: 2).
- async_polling_initial_delay (float): Initial polling delay in seconds for async operations (default: 0.1).
- async_polling_max_delay (float): Maximum polling delay cap in seconds for async operations (default: 1.0).
- async_polling_backoff_factor (float): Multiplier for exponential backoff in async polling (default: 2).
- proxies (dict): Dictionary with proxies, e.g. {'http': 'http://proxy.example.com:8080', 'https': 'http://secureproxy.example.com:8090'}.
- ssl_context: User-defined SSL context.
- cert (str|tuple): (Optional) If string, path to SSL client cert file (.pem). If tuple, ('cert', 'key') pair.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kwargs
|
See description above for all supported arguments |
{}
|
Source code in TM1py/Services/RestService.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | |
DEFAULT_CONNECTION_POOL_SIZE = 10
class-attribute
instance-attribute
DEFAULT_POOL_CONNECTIONS = 1
class-attribute
instance-attribute
HEADERS = {'Connection': 'keep-alive', 'User-Agent': 'TM1py', 'Content-Type': 'application/json; odata.streaming=true; charset=utf-8', 'Accept': 'application/json;odata.metadata=none,text/plain', 'TM1-SessionContext': 'TM1py'}
class-attribute
instance-attribute
is_admin
property
is_data_admin
property
is_ops_admin
property
is_security_admin
property
sandboxing_disabled
property
session_id
property
version
property
DELETE(url, data='', headers=None, async_requests_mode=None, return_async_id=False, timeout=None, cancel_at_timeout=False, encoding='utf-8', idempotent=False, verify_response=True, **kwargs)
Perform a DELETE request against TM1 instance
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
|
required |
data
|
Union[str, bytes, BytesIO]
|
the payload |
''
|
headers
|
Dict
|
custom headers |
None
|
async_requests_mode
|
bool
|
changes internal REST execution mode to avoid 60s timeout on IBM cloud |
None
|
return_async_id
|
bool
|
If True function will return async_id after initiation and not await the execution |
False
|
timeout
|
float
|
Number of seconds that the client will wait to receive the first byte. |
None
|
cancel_at_timeout
|
bool
|
Abort operation in TM1 when timeout is reached |
False
|
encoding
|
str
|
|
'utf-8'
|
Returns:
| Type | Description |
|---|---|
|
response object or async_id |
Source code in TM1py/Services/RestService.py
GET(url, data='', headers=None, async_requests_mode=None, return_async_id=False, timeout=None, cancel_at_timeout=False, encoding='utf-8', idempotent=True, verify_response=True, **kwargs)
Perform a GET request against TM1 instance
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
|
required |
data
|
Union[str, bytes, BytesIO]
|
the payload |
''
|
headers
|
Dict
|
custom headers |
None
|
async_requests_mode
|
bool
|
changes internal REST execution mode to avoid 60s timeout on IBM cloud |
None
|
return_async_id
|
bool
|
If True function will return async_id after initiation and not await the execution |
False
|
timeout
|
float
|
Number of seconds that the client will wait to receive the first byte. |
None
|
cancel_at_timeout
|
bool
|
Abort operation in TM1 when timeout is reached |
False
|
encoding
|
str
|
|
'utf-8'
|
Returns:
| Type | Description |
|---|---|
|
response object or async_id |
Source code in TM1py/Services/RestService.py
PATCH(url, data='', headers=None, async_requests_mode=None, return_async_id=False, timeout=None, cancel_at_timeout=False, encoding='utf-8', idempotent=False, verify_response=True, **kwargs)
Perform a PATCH request against TM1 instance
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
|
required |
data
|
Union[str, bytes, BytesIO]
|
the payload |
''
|
headers
|
Dict
|
custom headers |
None
|
async_requests_mode
|
bool
|
changes internal REST execution mode to avoid 60s timeout on IBM cloud |
None
|
return_async_id
|
bool
|
If True function will return async_id after initiation and not await the execution |
False
|
timeout
|
float
|
Number of seconds that the client will wait to receive the first byte. |
None
|
cancel_at_timeout
|
bool
|
Abort operation in TM1 when timeout is reached |
False
|
encoding
|
str
|
|
'utf-8'
|
Returns:
| Type | Description |
|---|---|
|
response object or async_id |
Source code in TM1py/Services/RestService.py
POST(url, data='', headers=None, async_requests_mode=None, return_async_id=False, timeout=None, cancel_at_timeout=False, encoding='utf-8', idempotent=False, verify_response=True, **kwargs)
Perform a POST request against TM1 instance
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
|
required |
data
|
Union[str, bytes, BytesIO]
|
the payload |
''
|
headers
|
Dict
|
custom headers |
None
|
async_requests_mode
|
bool
|
changes internal REST execution mode to avoid 60s timeout on IBM cloud |
None
|
return_async_id
|
bool
|
If True function will return async_id after initiation and not await the execution |
False
|
timeout
|
float
|
Number of seconds that the client will wait to receive the first byte. |
None
|
cancel_at_timeout
|
bool
|
Abort operation in TM1 when timeout is reached |
False
|
encoding
|
str
|
|
'utf-8'
|
Returns:
| Type | Description |
|---|---|
|
response object or async_id |
Source code in TM1py/Services/RestService.py
PUT(url, data='', headers=None, async_requests_mode=None, return_async_id=False, timeout=None, cancel_at_timeout=False, encoding='utf-8', idempotent=False, verify_response=True, **kwargs)
Perform a PUT request against TM1 instance
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
|
required |
data
|
Union[str, bytes, BytesIO]
|
the payload |
''
|
headers
|
Dict
|
custom headers |
None
|
async_requests_mode
|
bool
|
changes internal REST execution mode to avoid 60s timeout on IBM cloud |
None
|
return_async_id
|
bool
|
If True function will return async_id after initiation and not await the execution |
False
|
timeout
|
float
|
Number of seconds that the client will wait to receive the first byte. |
None
|
cancel_at_timeout
|
bool
|
Abort operation in TM1 when timeout is reached |
False
|
encoding
|
str
|
|
'utf-8'
|
Returns:
| Type | Description |
|---|---|
|
response object or async_id |
Source code in TM1py/Services/RestService.py
__exit__(exception_type, exception_value, traceback)
add_compact_json_header()
Source code in TM1py/Services/RestService.py
add_http_header(key, value)
b64_decode_password(encrypted_password)
staticmethod
b64 decoding
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encrypted_password
|
str
|
encrypted password with b64 |
required |
Returns:
| Type | Description |
|---|---|
str
|
password in plain text |
Source code in TM1py/Services/RestService.py
build_response_from_binary_response(data)
staticmethod
Source code in TM1py/Services/RestService.py
cancel_async_operation(async_id, **kwargs)
Source code in TM1py/Services/RestService.py
cancel_running_operation()
Source code in TM1py/Services/RestService.py
connect()
Source code in TM1py/Services/RestService.py
disable_http_warnings()
staticmethod
get_api_metadata()
Get API Metadata
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary |
get_http_header(key)
get_monitoring_service()
handle_logging(logging)
is_connected()
Check if Connection to TM1 Server is established. :Returns: Boolean
logout(timeout=None, **kwargs)
End TM1 Session and HTTP session
Source code in TM1py/Services/RestService.py
remove_http_header(key)
request(method, url, data='', encoding='utf-8', async_requests_mode=None, return_async_id=False, timeout=None, cancel_at_timeout=False, idempotent=False, verify_response=True, **kwargs)
Execute a request to TM1 REST API
Source code in TM1py/Services/RestService.py
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | |
retrieve_async_response(async_id, **kwargs)
set_version()
translate_to_boolean(value)
staticmethod
Takes a boolean or string (eg. true, True, FALSE, etc.) value and returns (boolean) True or False
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
True, 'true', 'false' or 'False' ... |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in TM1py/Services/RestService.py
urllib3_response_from_bytes(data)
staticmethod
Build urllib3.HTTPResponse based on raw bytes string
Source code in TM1py/Services/RestService.py
verify_response(response)
staticmethod
check if Status Code is OK
:Parameters:
response: String
the response that is returned from a method call
:Exceptions:
TM1pyException, raises TM1pyException when Code is not 200, 204 etc.
Source code in TM1py/Services/RestService.py
wait_time_generator(timeout)
Generate wait times for async polling with capped exponential backoff.
Uses configurable parameters: - async_polling_initial_delay: Starting delay - async_polling_max_delay: Maximum delay cap - async_polling_backoff_factor: Multiplier for each iteration
Default behavior (0.1s initial, 1.0s max, 2x factor) produces: 0.1s -> 0.2s -> 0.4s -> 0.8s -> 1.0s -> 1.0s -> ...