Skip to content

ObjectService

ObjectService(rest_service)

Parent class for all Object Services

Constructor, Create an instance of ObjectService

Parameters:

Name Type Description Default
rest_service RestService
required
Source code in TM1py/Services/ObjectService.py
def __init__(self, rest_service: RestService):
    """Constructor, Create an instance of ObjectService

    :param rest_service:
    """
    self._rest = rest_service
    if verify_version("12", self.version):
        self.binary_http_header = self.BINARY_HTTP_HEADER
    else:
        self.binary_http_header = self.BINARY_HTTP_HEADER_PRE_V12

BINARY_HTTP_HEADER = {'Content-Type': 'application/json;charset=UTF-8'} class-attribute instance-attribute

BINARY_HTTP_HEADER_PRE_V12 = {'Content-Type': 'application/octet-stream; odata.streaming=true'} class-attribute instance-attribute

ELEMENT_ATTRIBUTES_PREFIX = '}ElementAttributes_' class-attribute instance-attribute

SANDBOX_DIMENSION = 'Sandboxes' class-attribute instance-attribute

binary_http_header = self.BINARY_HTTP_HEADER instance-attribute

is_admin property

is_data_admin property

is_ops_admin property

is_security_admin property

version property

determine_actual_object_name(object_class, object_name, **kwargs)

Source code in TM1py/Services/ObjectService.py
def determine_actual_object_name(self, object_class: str, object_name: str, **kwargs) -> str:
    url = format_url(
        "/{}?$filter=tolower(replace(Name, ' ', '')) eq '{}'", object_class, object_name.replace(" ", "").lower()
    )
    response = self._rest.GET(url, **kwargs)

    if len(response.json()["value"]) == 0:
        raise ValueError("Object '{}' of type '{}' doesn't exist".format(object_name, object_class))

    return response.json()["value"][0]["Name"]

suggest_unique_object_name(random_seed=None)

Generate hash based on tm1-session-id, local-thread-id and random id to guarantee unique name avoids name conflicts in multithreading operations

Source code in TM1py/Services/ObjectService.py
def suggest_unique_object_name(self, random_seed: float = None) -> str:
    """
    Generate hash based on tm1-session-id, local-thread-id and random id to guarantee unique name
    avoids name conflicts in multithreading operations
    """
    if not random_seed:
        random_seed = random.random()
    unique_string = f"{self._rest.session_id}{threading.get_ident()}{random_seed}"
    unique_hash = "tm1py." + hashlib.sha256(unique_string.encode("utf-8")).hexdigest()[:12]
    return unique_hash