mstrio > python_execution > script

exception mstrio.python_execution.script.ScriptEnvironmentError

Bases: ScriptExecutionError

Exception raised when there is an environment-related error during script execution.

add_note(object, /)

Exception.add_note(note) – add a note to the exception

with_traceback(object, /)

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

args
exception mstrio.python_execution.script.ScriptError

Bases: Exception

Base Exception class for other exceptions in Scripts module.

Created for ease of catching all errors from this module, regardless of subtype. All other Exceptions in this module will inherit from it.

add_note(object, /)

Exception.add_note(note) – add a note to the exception

with_traceback(object, /)

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

args
exception mstrio.python_execution.script.ScriptExecutionError

Bases: ScriptError

Exception raised when a script execution fails.

add_note(object, /)

Exception.add_note(note) – add a note to the exception

with_traceback(object, /)

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

args
exception mstrio.python_execution.script.ScriptSetupError

Bases: ScriptError

Exception raised when a script is not properly set up for execution or saving.

add_note(object, /)

Exception.add_note(note) – add a note to the exception

with_traceback(object, /)

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

args
class mstrio.python_execution.script.Code(connection, code, validate_code=False)

Bases: object

Class representing Python code to be run in server-side execution engine of Strategy.

Note

To retrieve code-as-text from an instance of Code class, just use .as_text property or stringify the Code instance with str: ` >>> code = Code(conn, "print('Hello World')") >>> txt = str(code) >>> txt2 = code.as_text  # both equal "print('Hello World')" `

Parameters:
  • connection (Connection) –

  • code (Code | str) –

  • validate_code (bool) –

execute(runtime_id: str | None = None, variables: list[Variable | dict] | None = None, answers: VariablesAnswers | None = None, block_until_done: True = True, pipe_logs: bool = False, raise_on_execution_failure: bool = False, allow_interactive_answering: bool = False, variables_factory: type['Variable'] = None) ExecutionStatus
execute(runtime_id: str | None = None, variables: list[Variable | dict] | None = None, answers: VariablesAnswers | None = None, block_until_done: False = False, allow_interactive_answering: bool = False, variables_factory: type['Variable'] = None) None

Start Code execution.

Parameters:
  • runtime_id (str, optional) – ID of the Script runtime. If nothing is provided, defaults to Default Runtime.

  • variables (list[_Variable | dict], optional) – List of Variables to be used during Code execution.

  • answers (VariablesAnswers, optional) – Answers to prompted Variables. Can be either a list of VariableAnswer class instances, FlagKeepDefaultAnswer flags or a dict with shape: {“variable-id-or-name”: “answer-value”, …}.

  • block_until_done (bool, optional) – Whether to block the execution until it is done. Defaults to True.

  • pipe_logs (bool, optional) – Whether to pipe the execution logs to the logger while waiting for the execution to finish. Valid only if block_until_done is set. Defaults to False.

  • raise_on_execution_failure (bool, optional) – Whether to raise an exception if the execution fails. Valid only if block_until_done is set. Defaults to False.

  • allow_interactive_answering (bool, optional) – Whether to allow interactive answering of Variables if not all are answered. Defaults to False.

  • variables_factory (type[Variable], optional) – Factory class to use for creating Variable instances. Defaults to VariableStandardScript.

Returns:

if block_until_done is set to True. Nothing otherwise.

Return type:

ExecutionStatus

get_current_execution_status()

Retrieve current status of the code execution.

Returns:

Current status of the code execution, or None if

the code is not currently running.

Return type:

ExecutionStatus

get_execution_details()

Retrieve details about the current code execution.

Returns:

Details about the current code execution.

Return type:

dict

classmethod get_from_file(connection, path, validate_code=False)

Create Code instance from contents of a local file.

Note

Does not validate whether the path is correct, accessible or existing, so re-raises any OS-specific errors.

Parameters:
  • connection (Connection) – Strategy One connection object returned by connection.Connection().

  • path (Path | str) – Path to a file on your local drive containing the code. Example: C:Program FilesMy Scriptssome_script.py

  • validate_code (bool, optional) – Whether to validate the code syntax upon creation. Defaults to False. (This is a pre-run validation only and does not guarantee no Runtime Errors.)

Returns:

Created Code instance.

Return type:

Code

is_valid()

Check whether the code syntax is valid.

Note

This is a pre-run validation only and does not guarantee no Runtime Errors.

Returns:

True if the code syntax is valid, including Strategy-specific

extensions, like Variables. False otherwise.

Return type:

bool

stop_execution()

Stops the code execution.

Return type:

None

wait_for_execution_finish(pipe_logs=False, interval=None)

Wait until the code execution is finished.

Parameters:
  • pipe_logs (bool, optional) – Whether to pipe the execution logs of the Code to the console of this requester script. Defaults to False.

  • interval (int, optional) – Time interval in seconds between polling requests for status. If not provided, the value is taken from mstrio-py’s config.

Returns:

Final status of the code execution.

Return type:

ExecutionStatus

enum mstrio.python_execution.script.ExecutionStatus(value)

Bases: Enum

Valid values are as follows:

INITIATED = <ExecutionStatus.INITIATED: 0>
RUNNING = <ExecutionStatus.RUNNING: 1>
PARTIALLY_READY = <ExecutionStatus.PARTIALLY_READY: 2>
READY = <ExecutionStatus.READY: 3>
ERROR = <ExecutionStatus.ERROR: 4>
EXPIRED = <ExecutionStatus.EXPIRED: 5>
CANCELLED = <ExecutionStatus.CANCELLED: 6>

The Enum and its members also have the following methods:

classmethod is_done(value)
Parameters:

value (ExecutionStatus | int) –

Return type:

bool

classmethod is_error(value)
Parameters:

value (ExecutionStatus | int) –

Return type:

bool

class mstrio.python_execution.script.Script(connection, id=None, name=None)

Bases: Entity, DeleteMixin, MoveMixin, CopyMixin, CertifyMixin, ChangeJournalMixin

Class representing a Script object in Strategy.

Parameters:
  • connection (Connection) –

  • id (str | None) –

  • name (str | None) –

acl_add(rights, trustees, denied=False, inheritable=None, propagate_to_children=None, propagation_behavior=None)

Add Access Control Element (ACE) to the object ACL.

Note

To add rights for the Root Folder and the Freeform Objects, apply the required rights for these folders:

  • Root Folder: D43364C684E34A5F9B2F9AD7108F7828

  • Freeform Objects: 93D8CF3849C1F85DC1A48E8B9E4271F1

Argument propagate_to_children is used only for objects with type ObjectTypes.FOLDER.

Parameters:
  • rights (int | Rights | AggregatedRights) – The degree to which the user or group is granted or denied access to the object. The available permissions are defined in Rights and AggregatedRights Enums

  • trustees (list[UserOrGroup] | UserOrGroup) – list of trustees (User or UserGroup objects or ids) to update the ACE for

  • denied (bool) – flag to indicate granted or denied access to the object

  • inheritable (bool | None) – Applies only to folders. If set, any objects placed in the folder inherit the folder’s entry in the ACL.

  • propagate_to_children (bool | None) – used for folder objects only, default value is None, if set to True/False adds propagateACLToChildren keyword to the request body and sets its value accordingly

  • propagation_behavior (PropagationBehavior | str | None) – Behavior of ACL propagation to children.

  • self (Entity) –

Return type:

None

Examples

>>> obj.acl_add(rights=Rights.BROWSE | Rights.EXECUTE,
>>>             trustees=user_obj, denied=True)
acl_alter(rights, trustees, denied=False, inheritable=None, propagate_to_children=None, propagation_behavior=None)

Alter an existing Access Control Element (ACE) of the object ACL.

Note

To alter rights for the Root Folder and the Freeform Objects, change the required rights for these folders:

  • Root Folder: D43364C684E34A5F9B2F9AD7108F7828

  • Freeform Objects: 93D8CF3849C1F85DC1A48E8B9E4271F1

Argument propagate_to_children is used only for objects with type ObjectTypes.FOLDER.

Parameters:
  • rights (int | Rights | AggregatedRights) – The degree to which the user or group is granted or denied access to the object. The available permissions are defined in Rights and AggregatedRights Enums

  • trustees (list[UserOrGroup] | UserOrGroup) – list of trustees (User or UserGroup objects or ids) to update the ACE for

  • denied (bool) – flag to indicate granted or denied access to the object

  • inheritable (bool | None) – Applies only to folders. If set, any objects placed in the folder inherit the folder’s entry in the ACL.

  • propagate_to_children (bool | None) – used for folder objects only, default value is None, if set to True/False adds propagateACLToChildren keyword to the request body and sets its value accordingly

  • propagation_behavior (PropagationBehavior | str | None) – Behavior of ACL propagation to children.

  • self (Entity) –

Return type:

None

Examples

>>> obj.acl_alter(rights=Rights.BROWSE | Rights.EXECUTE,
>>>               trustees=user_obj, denied=True)
acl_remove(rights, trustees, denied=False, inheritable=None, propagate_to_children=None, propagation_behavior=None)

Remove Access Control Element (ACE) from the object ACL.

Note

To remove rights from the Root Folder and the Freeform Objects, remove them from these folders:

  • Root Folder: D43364C684E34A5F9B2F9AD7108F7828

  • Freeform Objects: 93D8CF3849C1F85DC1A48E8B9E4271F1

Argument propagate_to_children is used only for objects with type ObjectTypes.FOLDER.

Parameters:
  • rights (int | Rights | AggregatedRights) – The degree to which the user or group is granted or denied access to the object. The available permissions are defined in Rights and AggregatedRights Enums

  • trustees (list[UserOrGroup] | UserOrGroup) – list of trustees (User or UserGroup objects or ids) to update the ACE for

  • denied (bool) – flag to indicate granted or denied access to the object

  • inheritable (bool | None) – Applies only to folders. If set, any objects placed in the folder inherit the folder’s entry in the ACL.

  • propagate_to_children (bool | None) – used for folder objects only, default value is None, if set to True/False adds propagateACLToChildren keyword to the request body and sets its value accordingly

  • propagation_behavior (PropagationBehavior | str | None) – Behavior of ACL propagation to children.

  • self (Entity) –

Return type:

None

Examples

>>> obj.acl_remove(rights=Rights.BROWSE | Rights.EXECUTE,
>>>                trustees=user_obj, denied=True)
add_translation(translations)

Adds translations to the Object.

Parameters:
  • translations (list[OperationData]) – list of translations to be added to the Object

  • self (Entity) –

Returns:

A list of translations for the Object.

Return type:

list[’Translation’]

add_variables(*data)

Add Variables to the Script.

Note

This method makes sure that provided data for new Variables is correct and valid before applying changes. If valid, saves to both metadata and locally.

Parameters:

*data (Variable | dict) – Collected arbitrary amount of entries. For each Variable, an entry is either a Variable-class-based class instance or a dict with data to create a new Variable.

Return type:

None

Example: ```

>>> script.add_variables(
...     {
...         "name": "var1",
...         "type": VariableType.TEXT,
...     },
...     VariableStandardScript(
...         name="var2",
...         type=VariableType.NUMERICAL,
...         prompt=True,
...     ),
... )

```

alter(name=None, description=None, code=None, validate_code=False, runtime_id=None, variables=None, script_type=None, script_result_type=None)

Alter Script’s properties.

Note

Script Usage Type cannot be changed in an existing Script. One needs to create a new Script to “change” the Usage type.

Parameters:
  • name (str, optional) – New name of the Script.

  • description (str, optional) – New description of the Script.

  • code (Code | str, optional) – New code for the Script, either as Code class instance or as string (either already base64-encoded or original).

  • validate_code (bool, optional) – Whether to validate the code syntax before alteration. Defaults to False. Is ignored if code is not modified. (This is a pre-run validation only and does not guarantee no Runtime Errors.)

  • runtime_id (str, optional) – ID of the Script runtime.

  • variables (list[Variable | dict], optional) – List of Variables to be set for the Script.

  • script_type (ScriptType | str, optional) – Type of the Script.

  • script_result_type (ScriptResultType | str, optional) – Result type of the Script.

Return type:

None

alter_translation(translations)

Alters translations of the Object.

Parameters:
  • translations (list[OperationData]) – list of translations to be added to the Object

  • self (Entity) –

Return type:

None

alter_variables(changes=None)

Alter existing Variables on the Script.

Note

This method makes sure that provided data for Variables to be altered is correct and valid before applying changes. If valid, saves to both metadata and locally.

Parameters:

changes (dict[str, Variable | dict]) – Dictionary where keys are names or IDs of existing Variables to be altered, and values are either Variable-class-based class instances with new data or dicts with new data for the Variables.

Return type:

None

Example: ```

>>> script.alter_variables({
...     "var1": {
...         "name": "new_variable_name",
...         "type": VariableType.TEXT,
...     },
...     "var2": VariableStandardScript(
...         name="another_new_name",
...         type=VariableType.NUMERICAL,
...         prompt=True,
...     ),
... })

```

classmethod bulk_from_dict(source_list, connection=None, to_snake_case=True, with_missing_value=False)

Creates multiple objects from a list of dictionaries. For each dictionary provided the keys in camel case are changed to object’s attribute names (by default in snake case) and dict values are composed to their proper data types such as Enums, list of Enums etc. as specified in the object’s _FROM_DICT_MAP.

Parameters:
  • cls (T) – Class (type) of the objects that should be created.

  • source_list (List[Dict[str, Any]]) – A list of dictionaries from which the objects will be constructed.

  • connection (Connection, optional) – A MSTR Connection object. Defaults to None.

  • to_snake_case (bool, optional) – Set to True if attribute names should be converted from camel case to snake case. Defaults to True.

  • with_missing_value (bool) – (bool, optional): If True, class attributes possible to fetch and missing in source will be set as MissingValue objects.

Returns:

A list of objects of type T.

Return type:

T

certify()

Certify object.

Parameters:
  • success_msg – Custom message displayed on success.

  • self (Entity) –

Returns:

True on success, False otherwise.

Return type:

bool

classmethod create(connection, name, runtime_id, code, destination_folder=None, destination_folder_path=None, description=None, variables=None, script_type=ScriptType.PYTHON, script_usage_type=ScriptUsageType.STANDARD, script_result_type=None, validate_code=False)

Create a new Script in Strategy.

Parameters:
  • connection (Connection) – Strategy connection object returned by connection.Connection().

  • name (str) – Name of the Script.

  • runtime_id (str) – ID of the Script runtime.

  • code (Code | str) – Code class instance or code as a string, either base64-encoded or not

  • destination_folder (Folder | tuple | list | str, optional) – Folder object or ID or name or path specifying the folder where to create object.

  • destination_folder_path (str, optional) –

    Path of the folder. The path has to be provided in the following format:

    /MicroStrategy Tutorial/Public Objects/Python Scripts

  • description (str, optional) – Description of the Script.

  • variables (list[Variable | dict], optional) – List of Variables’ definitions (as raw dicts or as Variable class instances) to be saved in metadata of the Script.

  • script_type (ScriptType | str, optional) – Type of the Script. Defaults to ScriptType.PYTHON.

  • script_usage_type (ScriptUsageType | str, optional) – Usage type of the Script. Defaults to ScriptUsageType.STANDARD.

  • script_result_type (ScriptResultType | str, optional) – Result type of the Script. Defaults to None.

  • validate_code (bool, optional) – Whether to validate the code syntax before Script creation. Defaults to False. (This is a pre-run validation only and does not guarantee no Runtime Errors.)

Returns:

Created Script class instance object.

Return type:

Script

create_copy(name=None, folder_id=None, project=None)

Create a copy of the object on the I-Server.

Parameters:
  • name (str | None) – New name of the object. If None, a default name is generated, such as ‘Old Name (1)’

  • folder_id (str | None) – ID of the destination folder. If None, the object is saved in the same folder as the source object.

  • project (Project | str | None) – By default, the project selected when creating Connection object. Override project to specify project where the current object exists.

  • self (Entity[T]) –

Returns:

New python object holding the copied object.

Return type:

T

create_shortcut(target_folder=None, target_folder_id=None, target_folder_name=None, target_folder_path=None, project=None, project_id=None, project_name=None, to_dictionary=False)

Create a shortcut to the object.

Parameters:
  • target_folder (Folder | tuple | list | str, optional) – Folder object or ID or name or path specifying the folder. May be used instead of target_folder_id, target_folder_name or target_folder_path.

  • target_folder_id (str, optional) – ID of a folder.

  • target_folder_name (str, optional) – Name of a folder.

  • target_folder_path (str, optional) –

    Path of the folder. The path has to be provided in the following format:

    /MicroStrategy Tutorial/Public Objects/Metrics

  • project (Project | str, optional) – Project object or ID or name specifying the project. May be used instead of project_id or project_name.

  • project_id (str, optional) – Project ID

  • project_name (str, optional) – Project name

  • to_dictionary (bool, optional) – If True, the method will return a dictionary with the shortcut’s properties instead of a Shortcut object. Defaults to False.

Return type:

Shortcut

decertify()

Decertify object.

Parameters:
  • success_msg – Custom message displayed on success.

  • self (Entity) –

Returns:

True on success, False otherwise.

Return type:

bool

delete(force=False, journal_comment=None, **kwargs)

Delete object.

Parameters:
  • force (bool) – If True, then no additional prompt will be shown before deleting object.

  • journal_comment (str | None) – Comment to be added to the change journal for this deletion. If None, no comment is added.

  • **kwargs – Any additional arguments within overridden versions of this method in inheritance chain.

  • self (Entity) –

Returns:

True on success. False otherwise.

Return type:

bool

delete_variables(*data)

Delete Variables from the Script.

Note

This method makes sure that provided data for Variables to be deleted is correct and valid before applying changes. If valid, saves to both metadata and locally.

Parameters:

*data (Variable | str) – Collected arbitrary amount of entries. For each Variable to be deleted, an entry is either a Variable-class-based class instance or the name/ID of the Variable as a string.

Return type:

None

Example: ```

>>> script.delete_variables(
...     "var1",
...     VariableStandardScript(
...         name="var2",
...     ),
... )

```

execute(block_until_done: True = True, pipe_logs: bool = False, raise_on_execution_failure: bool = False, variables_answers: VariablesAnswers | None = None, save_answers_as_personal: bool = False, allow_interactive_answering: bool = False) ExecutionStatus
execute(block_until_done: False = False, variables_answers: VariablesAnswers | None = None, save_answers_as_personal: bool = False, allow_interactive_answering: bool = False) None

Start Script execution.

Parameters:
  • block_until_done (bool, optional) – Whether to block the execution until it is done. Defaults to True.

  • pipe_logs (bool, optional) – Whether to pipe the execution logs to the logger while waiting for the execution to finish. Valid only if block_until_done is set. Defaults to False.

  • raise_on_execution_failure (bool, optional) – Whether to raise an exception if the execution fails. Valid only if block_until_done is set. Defaults to False.

  • allow_interactive_answering (bool, optional) – Whether to allow interactive answering of Variables if not all are answered. Defaults to False.

Returns:

if block_until_done is set to True. Nothing otherwise.

Return type:

ExecutionStatus

fetch(attr=None)

Fetch the latest object’s state from the I-Server.

Note

This method can overwrite local changes made to the object.

Parameters:
  • attr (Optional[str]) – Attribute name to be fetched. If not specified

  • dictionary. (it will use all getters specified in _API_GETTERS) –

  • None. (Defaults to) –

Raises:

ValueError – If attr cannot be fetched.

Return type:

None

fetch_all_change_journal_entries()

Fetch change journal entries from the API.

Return type:

None

classmethod from_dict(source, connection, to_snake_case=True, with_missing_value=False)
Overrides Dictable.from_dict() to instantiate an object from

a dictionary without calling any additional getters.

Parameters:
  • cls – Class (type) of an object that should be created.

  • source (dict[str, Any]) – a dictionary from which an object will be constructed.

  • connection (Connection) – A Strategy One Connection object.

  • to_snake_case (bool, optional) – Set to True if attribute names should be converted from camel case to snake case, default True.

  • with_missing_value (bool) – (bool, optional): If True, class attributes possible to fetch and missing in source will be set as MissingValue objects.

Returns:

An instance of the cls class.

get(name)

Get object’s attribute by its name.

get_execution_details()

Retrieve details about the Script current execution.

Note

This property reads from Current Execution, hence refer to last run of the Script done by you specifically.

Returns:

Details about the Script current execution.

Return type:

dict

get_execution_status()

Retrieve current status of the Script execution.

Returns:

Current status of the Script execution, or None if

the Script is not currently running.

Return type:

ExecutionStatus

get_last_run_details()

Gets the details about the last run of the Script, if any, including execution time, status and logs of the run.

Note

This property reads from Run History, hence refer to last run of the Script overall, not necessarily your last run of this Script.

Returns:

Dictionary with data about the last run of the Script,

or empty dictionary if there is no history.

Return type:

dict

get_variables()

Get Variables saved in metadata of the Script.

Returns:

Tuple of Variables associated with the Script.

Return type:

tuple[Variable]

has_dependents()

Check if the object has any dependents.

Returns:

True if the object has dependents, False otherwise.

Parameters:

self (Entity) –

Return type:

bool

list_acl(to_dataframe=False, to_dictionary=False, **filters)

Get Access Control List (ACL) for this object. Optionally filter ACLs by specifying filters.

Parameters:
  • to_dataframe (bool, optional) – if True, return datasets as pandas DataFrame

  • to_dictionary (bool, optional) – if True, return datasets as dicts

  • **filters – Available filter parameters: [deny, type, rights, trustee_id, trustee_name, trustee_type, trustee_subtype, inheritable]

Return type:

DataFrame | list[dict | mstrio.utils.acl.ACE]

Examples

>>> list_acl(deny=True, trustee_name="John")
list_dependencies(project=None, name=None, pattern=4, domain=2, scope=None, object_types=None, used_by_recursive=False, root=None, root_path=None, limit=None, offset=None, results_format='LIST', to_dictionary=True, **filters)

List list_dependencies of an object.

Parameters:
  • project (string) – Project object or ID

  • name (string) – Value the search pattern is set to, which will be applied to the names of object types being searched. For example, search for all report objects (type) whose name begins with (pattern) B (name).

  • pattern (integer or enum class object) – Pattern to search for, such as Begin With or Exactly. Possible values are available in ENUM mstrio.object_management.SearchPattern. Default value is CONTAINS (4).

  • domain (integer or enum class object) – Domain where the search will be performed, such as Local or Project. Possible values are available in ENUM mstrio.object_management.SearchDomain. Default value is PROJECT (2).

  • scope (SearchScope, str, optional) – Scope of the search with regard to System Managed Objects. Possible values are available in ENUM mstrio.object_management.SearchScope.

  • root (string, optional) – Folder ID of the root folder where the search will be performed.

  • root_path (str, optional) –

    Path of the root folder in which the search will be performed. Can be provided as an alternative to root parameter. If both are provided, root is used.

    the path has to be provided in the following format:
    if it’s inside of a project, example:

    /MicroStrategy Tutorial/Public Objects/Metrics

    if it’s a root folder, example:

    /CASTOR_SERVER_CONFIGURATION/Users

  • class (object_types(enum class object or integer or list of enum) – objects or integers): Type(s) of object(s) to be searched, such as Folder, Attribute or User. Possible values available in ENUMs mstrio.types.ObjectTypes and mstrio.types.ObjectSubTypes

  • used_by_recursive (boolean, optional) – Control the Intelligence server to also find objects that are used by the given objects indirectly. Default value is false.

  • results_format (SearchResultsFormat) – either a list or a tree format

  • to_dictionary (bool) – If False returns objects, by default (True) returns dictionaries.

  • limit (int) – limit the number of elements returned. If None (default), all objects are returned.

  • offset (int) – Starting point within the collection of returned results. Used to control paging behavior. Default is 0.

  • **filters – Available filter parameters: [‘id’, ‘name’, ‘description’, ‘date_created’, ‘date_modified’, ‘acg’]

  • self (Entity) –

  • object_types (TypeOrSubtype | None) –

Returns:

list of objects or list of dictionaries

list_dependents(project=None, name=None, pattern=4, domain=2, scope=None, object_types=None, uses_recursive=False, root=None, root_path=None, limit=None, offset=None, results_format='LIST', to_dictionary=True, **filters)

List dependents of an object.

Parameters:
  • project (string) – Project object or ID

  • name (string) – Value the search pattern is set to, which will be applied to the names of object types being searched. For example, search for all report objects (type) whose name begins with (pattern) B (name).

  • pattern (integer or enum class object) – Pattern to search for, such as Begin With or Exactly. Possible values are available in ENUM mstrio.object_management.SearchPattern. Default value is CONTAINS (4).

  • domain (integer or enum class object) – Domain where the search will be performed, such as Local or Project. Possible values are available in ENUM mstrio.object_management.SearchDomain. Default value is PROJECT (2).

  • scope (SearchScope, str, optional) – Scope of the search with regard to System Managed Objects. Possible values are available in ENUM mstrio.object_management.SearchScope.

  • root (string, optional) – Folder ID of the root folder where the search will be performed.

  • root_path (str, optional) – Path of the root folder in which the search will be performed. Can be provided as an alternative to root parameter. If both are provided, root is used. the path has to be provided in the following format: >>> # if it’s inside of a project, example: >>> /MicroStrategy Tutorial/Public Objects/Metrics >>> # if it’s a root folder, example: >>> /CASTOR_SERVER_CONFIGURATION/Users

  • class (object_types (enum class object or integer or list of enum) – objects or integers): Type(s) of object(s) to be searched, such as Folder, Attribute or User. Possible values available in ENUMs mstrio.types.ObjectTypes and mstrio.types.ObjectSubTypes

  • uses_recursive (boolean) – Control the Intelligence server to also find objects that use the given objects indirectly. Default value is false.

  • results_format (SearchResultsFormat) – either a list or a tree format

  • to_dictionary (bool) – If False returns objects, by default (True) returns dictionaries.

  • limit (int) – limit the number of elements returned. If None (default), all objects are returned.

  • offset (int) – Starting point within the collection of returned results. Used to control paging behavior. Default is 0.

  • **filters – Available filter parameters: [‘id’, ‘name’, ‘description’, ‘date_created’, ‘date_modified’, ‘acg’]

  • self (Entity) –

  • object_types (TypeOrSubtype | None) –

Returns:

list of objects or list of dictionaries

Return type:

list[dict] | list[’Entity’]

list_properties(excluded_properties=None)

Fetches all attributes from the server and converts all properties of the object to a dictionary.

Parameters:

excluded_properties (list[str], optional) – A list of object properties that should be excluded from the dict. Defaults to None.

Returns:

A dictionary which keys are object’s attribute names, and

which values are object’s attribute values.

Return type:

dict

list_translations(languages=None, to_dictionary=False)

Lists translations for the Object.

Parameters:
  • languages (list, optional) –

    list of languages to list the translations for, only translations from these languages will be listed. Languages in the list should be one of the following:

    • lcid attribute of the language

    • ID of the language

    • Language class object

  • to_dictionary (bool, optional) – If True returns dict, by default (False) returns Translation objects

  • self (Entity) –

Returns:

A list of dictionaries representing translations for the Object or a list of Translation Objects.

Return type:

list[’Translation’] | list[dict]

move(folder=None, folder_id=None, folder_name=None, folder_path=None)

Move the object to a folder on the I-Server.

Parameters:
  • folder (Folder | tuple | list | str, optional) – Folder object or ID or name or path specifying the folder. May be used instead of folder_id, folder_name or folder_path.

  • folder_id (str, optional) – ID of a folder.

  • folder_name (str, optional) – Name of a folder.

  • folder_path (str, optional) –

    Path of the folder. The path has to be provided in the following format:

    if it’s inside of a project, start with a Project Name:

    /MicroStrategy Tutorial/Public Objects/Metrics

    if it’s a root folder, start with CASTOR_SERVER_CONFIGURATION:

    /CASTOR_SERVER_CONFIGURATION/Users

  • self (Entity) –

Return type:

None

print()

Pretty Print all properties of the object.

Return type:

None

remove_translation(translations)

Removes translations from the Object.

Parameters:
  • translations (list[OperationData]) – list of translations to be added to the Object

  • self (Entity) –

Return type:

None

save_personal_variable_answers(answers)

Save provided answers as personal default answers for Variables on the Script.

Note

If some prompted Variables are not answered, current global default value for them will be used as your personal default. This is due to the REST API call requiring all prompted Variables to be provided at once.

Parameters:

answers (VariablesAnswers) – Answers to be saved as personal default answers for Variables on the Script.

Return type:

None

stop_execution()

Stops the Script execution.

Return type:

None

classmethod to_csv(objects, name, path=None, properties=None)

Exports MSTR objects to a csv file.

Optionally, saves only the object properties specified in the properties parameter.

Parameters:
  • objects (T | list[T]) – List of objects of the same type that

  • exported. (will be) –

  • name (str) – The name of the csv file ending with ‘.csv’

  • path (Optional[str], optional) – A path to the directory where the file will be saved. Defaults to None.

  • properties (Optional[list[str]], optional) – A list of object’s attribute names that should be included in the exported file. Defaults to None.

Raises:
  • TypeError – If objects is not of type T or list of type T

  • objects.

Return type:

None

to_dataframe()

Converts all properties of the object to a dataframe.

Returns:

A DataFrame object containing object properties.

Return type:

DataFrame

to_dict(camel_case=True)

Converts an object to a dictionary excluding object’s private properties. When converting the object to a dictionary, the object’s attributes become the dictionary’s keys and are in camel case by default Attribute values stored as objects are automatically converted to non-/ primitive data structures.

Parameters:
  • camel_case (bool, optional) – Set to True if attribute names should be converted from snake case to camel case. Defaults to True.

  • whitelist_keys (list[str], optional) – List of keys to include in the resulting dictionary. If None, all keys (except hidden ones) are included. Defaults to None.

  • skip_private_keys (bool, optional) – If True, skips private keys in final dict representation.

Returns:

A dictionary representation of object’s attributes and values.

By default, the dictionary keys are in camel case.

Return type:

dict

update_properties()

Save compatible local changes of the object attributes to the I-Server. Changes are retrieved from the self._altered_properties dictionary. After the process of update has finished, self._altered_properties is cleared. For this method to work properly, you must override the _alter_properties() method in a subclass.

Raises:

requests.HTTPError – If I-Server raises exception

Return type:

None

wait_for_execution_finish(pipe_logs=False, interval=None)

Wait until the Script execution is finished.

Parameters:
  • pipe_logs (bool, optional) – Whether to pipe the execution logs of the Script to the console of this requester script. Defaults to False.

  • interval (int, optional) – Time interval in seconds between polling requests for status. If not provided, the value is taken from mstrio-py’s config.

Returns:

Final status of the Script execution.

Return type:

ExecutionStatus

enum mstrio.python_execution.script.ScriptResultType(value)

Bases: AutoName

Type of Script’s output

Valid values are as follows:

NUMERICAL = ScriptResultType.NUMERICAL
TEXT = ScriptResultType.TEXT
DATE = ScriptResultType.DATE
RESERVED = ScriptResultType.RESERVED
UNKNOWN = ScriptResultType.UNKNOWN
enum mstrio.python_execution.script.ScriptType(value)

Bases: Enum

Valid values are as follows:

RESERVED = <ScriptType.RESERVED: 'reserved'>
PYTHON = <ScriptType.PYTHON: 'python'>
JUPYTER_NOTEBOOK = <ScriptType.JUPYTER_NOTEBOOK: 'jupyterNotebook'>
enum mstrio.python_execution.script.ScriptUsageType(value)

Bases: Enum

Valid values are as follows:

STANDARD = <ScriptUsageType.STANDARD: 'commandManager'>
DATASOURCE = <ScriptUsageType.DATASOURCE: 'dataSource'>
TRANSACTION = <ScriptUsageType.TRANSACTION: 'transaction'>
SIMPLE_FUNCTION = <ScriptUsageType.SIMPLE_FUNCTION: 'pythonSimpleFunction'>
AGGREGATION_FUNCTION = <ScriptUsageType.AGGREGATION_FUNCTION: 'pythonAggFunction'>
AGGREGATION_FUNCTION_NO_SORT = <ScriptUsageType.AGGREGATION_FUNCTION_NO_SORT: 'pythonNoSortAggFunction'>
RELATIVE_FUNCTION = <ScriptUsageType.RELATIVE_FUNCTION: 'pythonRelativeFunction'>
RELATIVE_FUNCTION_NO_SORT = <ScriptUsageType.RELATIVE_FUNCTION_NO_SORT: 'pythonNoSortRelativeFunction'>
class mstrio.python_execution.script.SystemPrompt(connection, id)

Bases: Entity

Simple representation of a System Prompt object.

Parameters:
acl_add(rights, trustees, denied=False, inheritable=None, propagate_to_children=None, propagation_behavior=None)

Add Access Control Element (ACE) to the object ACL.

Note

To add rights for the Root Folder and the Freeform Objects, apply the required rights for these folders:

  • Root Folder: D43364C684E34A5F9B2F9AD7108F7828

  • Freeform Objects: 93D8CF3849C1F85DC1A48E8B9E4271F1

Argument propagate_to_children is used only for objects with type ObjectTypes.FOLDER.

Parameters:
  • rights (int | Rights | AggregatedRights) – The degree to which the user or group is granted or denied access to the object. The available permissions are defined in Rights and AggregatedRights Enums

  • trustees (list[UserOrGroup] | UserOrGroup) – list of trustees (User or UserGroup objects or ids) to update the ACE for

  • denied (bool) – flag to indicate granted or denied access to the object

  • inheritable (bool | None) – Applies only to folders. If set, any objects placed in the folder inherit the folder’s entry in the ACL.

  • propagate_to_children (bool | None) – used for folder objects only, default value is None, if set to True/False adds propagateACLToChildren keyword to the request body and sets its value accordingly

  • propagation_behavior (PropagationBehavior | str | None) – Behavior of ACL propagation to children.

  • self (Entity) –

Return type:

None

Examples

>>> obj.acl_add(rights=Rights.BROWSE | Rights.EXECUTE,
>>>             trustees=user_obj, denied=True)
acl_alter(rights, trustees, denied=False, inheritable=None, propagate_to_children=None, propagation_behavior=None)

Alter an existing Access Control Element (ACE) of the object ACL.

Note

To alter rights for the Root Folder and the Freeform Objects, change the required rights for these folders:

  • Root Folder: D43364C684E34A5F9B2F9AD7108F7828

  • Freeform Objects: 93D8CF3849C1F85DC1A48E8B9E4271F1

Argument propagate_to_children is used only for objects with type ObjectTypes.FOLDER.

Parameters:
  • rights (int | Rights | AggregatedRights) – The degree to which the user or group is granted or denied access to the object. The available permissions are defined in Rights and AggregatedRights Enums

  • trustees (list[UserOrGroup] | UserOrGroup) – list of trustees (User or UserGroup objects or ids) to update the ACE for

  • denied (bool) – flag to indicate granted or denied access to the object

  • inheritable (bool | None) – Applies only to folders. If set, any objects placed in the folder inherit the folder’s entry in the ACL.

  • propagate_to_children (bool | None) – used for folder objects only, default value is None, if set to True/False adds propagateACLToChildren keyword to the request body and sets its value accordingly

  • propagation_behavior (PropagationBehavior | str | None) – Behavior of ACL propagation to children.

  • self (Entity) –

Return type:

None

Examples

>>> obj.acl_alter(rights=Rights.BROWSE | Rights.EXECUTE,
>>>               trustees=user_obj, denied=True)
acl_remove(rights, trustees, denied=False, inheritable=None, propagate_to_children=None, propagation_behavior=None)

Remove Access Control Element (ACE) from the object ACL.

Note

To remove rights from the Root Folder and the Freeform Objects, remove them from these folders:

  • Root Folder: D43364C684E34A5F9B2F9AD7108F7828

  • Freeform Objects: 93D8CF3849C1F85DC1A48E8B9E4271F1

Argument propagate_to_children is used only for objects with type ObjectTypes.FOLDER.

Parameters:
  • rights (int | Rights | AggregatedRights) – The degree to which the user or group is granted or denied access to the object. The available permissions are defined in Rights and AggregatedRights Enums

  • trustees (list[UserOrGroup] | UserOrGroup) – list of trustees (User or UserGroup objects or ids) to update the ACE for

  • denied (bool) – flag to indicate granted or denied access to the object

  • inheritable (bool | None) – Applies only to folders. If set, any objects placed in the folder inherit the folder’s entry in the ACL.

  • propagate_to_children (bool | None) – used for folder objects only, default value is None, if set to True/False adds propagateACLToChildren keyword to the request body and sets its value accordingly

  • propagation_behavior (PropagationBehavior | str | None) – Behavior of ACL propagation to children.

  • self (Entity) –

Return type:

None

Examples

>>> obj.acl_remove(rights=Rights.BROWSE | Rights.EXECUTE,
>>>                trustees=user_obj, denied=True)
add_translation(translations)

Adds translations to the Object.

Parameters:
  • translations (list[OperationData]) – list of translations to be added to the Object

  • self (Entity) –

Returns:

A list of translations for the Object.

Return type:

list[’Translation’]

alter_translation(translations)

Alters translations of the Object.

Parameters:
  • translations (list[OperationData]) – list of translations to be added to the Object

  • self (Entity) –

Return type:

None

classmethod bulk_from_dict(source_list, connection=None, to_snake_case=True, with_missing_value=False)

Creates multiple objects from a list of dictionaries. For each dictionary provided the keys in camel case are changed to object’s attribute names (by default in snake case) and dict values are composed to their proper data types such as Enums, list of Enums etc. as specified in the object’s _FROM_DICT_MAP.

Parameters:
  • cls (T) – Class (type) of the objects that should be created.

  • source_list (List[Dict[str, Any]]) – A list of dictionaries from which the objects will be constructed.

  • connection (Connection, optional) – A MSTR Connection object. Defaults to None.

  • to_snake_case (bool, optional) – Set to True if attribute names should be converted from camel case to snake case. Defaults to True.

  • with_missing_value (bool) – (bool, optional): If True, class attributes possible to fetch and missing in source will be set as MissingValue objects.

Returns:

A list of objects of type T.

Return type:

T

create_shortcut(target_folder=None, target_folder_id=None, target_folder_name=None, target_folder_path=None, project=None, project_id=None, project_name=None, to_dictionary=False)

Create a shortcut to the object.

Parameters:
  • target_folder (Folder | tuple | list | str, optional) – Folder object or ID or name or path specifying the folder. May be used instead of target_folder_id, target_folder_name or target_folder_path.

  • target_folder_id (str, optional) – ID of a folder.

  • target_folder_name (str, optional) – Name of a folder.

  • target_folder_path (str, optional) –

    Path of the folder. The path has to be provided in the following format:

    /MicroStrategy Tutorial/Public Objects/Metrics

  • project (Project | str, optional) – Project object or ID or name specifying the project. May be used instead of project_id or project_name.

  • project_id (str, optional) – Project ID

  • project_name (str, optional) – Project name

  • to_dictionary (bool, optional) – If True, the method will return a dictionary with the shortcut’s properties instead of a Shortcut object. Defaults to False.

Return type:

Shortcut

fetch(attr=None)

Fetch the latest object’s state from the I-Server.

Note

This method can overwrite local changes made to the object.

Parameters:
  • attr (Optional[str]) – Attribute name to be fetched. If not specified

  • dictionary. (it will use all getters specified in _API_GETTERS) –

  • None. (Defaults to) –

Raises:

ValueError – If attr cannot be fetched.

Return type:

None

fetch_all_change_journal_entries()

Fetch change journal entries from the API.

Return type:

None

classmethod from_dict(source, connection, to_snake_case=True, with_missing_value=False)
Overrides Dictable.from_dict() to instantiate an object from

a dictionary without calling any additional getters.

Parameters:
  • cls – Class (type) of an object that should be created.

  • source (dict[str, Any]) – a dictionary from which an object will be constructed.

  • connection (Connection) – A Strategy One Connection object.

  • to_snake_case (bool, optional) – Set to True if attribute names should be converted from camel case to snake case, default True.

  • with_missing_value (bool) – (bool, optional): If True, class attributes possible to fetch and missing in source will be set as MissingValue objects.

Returns:

An instance of the cls class.

get(name)

Get object’s attribute by its name.

static get_all(conn)

Get all System Prompts available in the System Prompts Folder.

Parameters:

conn (Connection) –

Return type:

list[’SystemPrompt’]

static get_by_name(conn, name)

Get System Prompt by its name.

Parameters:
Return type:

SystemPrompt

has_dependents()

Check if the object has any dependents.

Returns:

True if the object has dependents, False otherwise.

Parameters:

self (Entity) –

Return type:

bool

list_acl(to_dataframe=False, to_dictionary=False, **filters)

Get Access Control List (ACL) for this object. Optionally filter ACLs by specifying filters.

Parameters:
  • to_dataframe (bool, optional) – if True, return datasets as pandas DataFrame

  • to_dictionary (bool, optional) – if True, return datasets as dicts

  • **filters – Available filter parameters: [deny, type, rights, trustee_id, trustee_name, trustee_type, trustee_subtype, inheritable]

Return type:

DataFrame | list[dict | mstrio.utils.acl.ACE]

Examples

>>> list_acl(deny=True, trustee_name="John")
list_dependencies(project=None, name=None, pattern=4, domain=2, scope=None, object_types=None, used_by_recursive=False, root=None, root_path=None, limit=None, offset=None, results_format='LIST', to_dictionary=True, **filters)

List list_dependencies of an object.

Parameters:
  • project (string) – Project object or ID

  • name (string) – Value the search pattern is set to, which will be applied to the names of object types being searched. For example, search for all report objects (type) whose name begins with (pattern) B (name).

  • pattern (integer or enum class object) – Pattern to search for, such as Begin With or Exactly. Possible values are available in ENUM mstrio.object_management.SearchPattern. Default value is CONTAINS (4).

  • domain (integer or enum class object) – Domain where the search will be performed, such as Local or Project. Possible values are available in ENUM mstrio.object_management.SearchDomain. Default value is PROJECT (2).

  • scope (SearchScope, str, optional) – Scope of the search with regard to System Managed Objects. Possible values are available in ENUM mstrio.object_management.SearchScope.

  • root (string, optional) – Folder ID of the root folder where the search will be performed.

  • root_path (str, optional) –

    Path of the root folder in which the search will be performed. Can be provided as an alternative to root parameter. If both are provided, root is used.

    the path has to be provided in the following format:
    if it’s inside of a project, example:

    /MicroStrategy Tutorial/Public Objects/Metrics

    if it’s a root folder, example:

    /CASTOR_SERVER_CONFIGURATION/Users

  • class (object_types(enum class object or integer or list of enum) – objects or integers): Type(s) of object(s) to be searched, such as Folder, Attribute or User. Possible values available in ENUMs mstrio.types.ObjectTypes and mstrio.types.ObjectSubTypes

  • used_by_recursive (boolean, optional) – Control the Intelligence server to also find objects that are used by the given objects indirectly. Default value is false.

  • results_format (SearchResultsFormat) – either a list or a tree format

  • to_dictionary (bool) – If False returns objects, by default (True) returns dictionaries.

  • limit (int) – limit the number of elements returned. If None (default), all objects are returned.

  • offset (int) – Starting point within the collection of returned results. Used to control paging behavior. Default is 0.

  • **filters – Available filter parameters: [‘id’, ‘name’, ‘description’, ‘date_created’, ‘date_modified’, ‘acg’]

  • self (Entity) –

  • object_types (TypeOrSubtype | None) –

Returns:

list of objects or list of dictionaries

list_dependents(project=None, name=None, pattern=4, domain=2, scope=None, object_types=None, uses_recursive=False, root=None, root_path=None, limit=None, offset=None, results_format='LIST', to_dictionary=True, **filters)

List dependents of an object.

Parameters:
  • project (string) – Project object or ID

  • name (string) – Value the search pattern is set to, which will be applied to the names of object types being searched. For example, search for all report objects (type) whose name begins with (pattern) B (name).

  • pattern (integer or enum class object) – Pattern to search for, such as Begin With or Exactly. Possible values are available in ENUM mstrio.object_management.SearchPattern. Default value is CONTAINS (4).

  • domain (integer or enum class object) – Domain where the search will be performed, such as Local or Project. Possible values are available in ENUM mstrio.object_management.SearchDomain. Default value is PROJECT (2).

  • scope (SearchScope, str, optional) – Scope of the search with regard to System Managed Objects. Possible values are available in ENUM mstrio.object_management.SearchScope.

  • root (string, optional) – Folder ID of the root folder where the search will be performed.

  • root_path (str, optional) – Path of the root folder in which the search will be performed. Can be provided as an alternative to root parameter. If both are provided, root is used. the path has to be provided in the following format: >>> # if it’s inside of a project, example: >>> /MicroStrategy Tutorial/Public Objects/Metrics >>> # if it’s a root folder, example: >>> /CASTOR_SERVER_CONFIGURATION/Users

  • class (object_types (enum class object or integer or list of enum) – objects or integers): Type(s) of object(s) to be searched, such as Folder, Attribute or User. Possible values available in ENUMs mstrio.types.ObjectTypes and mstrio.types.ObjectSubTypes

  • uses_recursive (boolean) – Control the Intelligence server to also find objects that use the given objects indirectly. Default value is false.

  • results_format (SearchResultsFormat) – either a list or a tree format

  • to_dictionary (bool) – If False returns objects, by default (True) returns dictionaries.

  • limit (int) – limit the number of elements returned. If None (default), all objects are returned.

  • offset (int) – Starting point within the collection of returned results. Used to control paging behavior. Default is 0.

  • **filters – Available filter parameters: [‘id’, ‘name’, ‘description’, ‘date_created’, ‘date_modified’, ‘acg’]

  • self (Entity) –

  • object_types (TypeOrSubtype | None) –

Returns:

list of objects or list of dictionaries

Return type:

list[dict] | list[’Entity’]

list_properties(excluded_properties=None)

Fetches all attributes from the server and converts all properties of the object to a dictionary.

Parameters:

excluded_properties (list[str], optional) – A list of object properties that should be excluded from the dict. Defaults to None.

Returns:

A dictionary which keys are object’s attribute names, and

which values are object’s attribute values.

Return type:

dict

list_translations(languages=None, to_dictionary=False)

Lists translations for the Object.

Parameters:
  • languages (list, optional) –

    list of languages to list the translations for, only translations from these languages will be listed. Languages in the list should be one of the following:

    • lcid attribute of the language

    • ID of the language

    • Language class object

  • to_dictionary (bool, optional) – If True returns dict, by default (False) returns Translation objects

  • self (Entity) –

Returns:

A list of dictionaries representing translations for the Object or a list of Translation Objects.

Return type:

list[’Translation’] | list[dict]

print()

Pretty Print all properties of the object.

Return type:

None

remove_translation(translations)

Removes translations from the Object.

Parameters:
  • translations (list[OperationData]) – list of translations to be added to the Object

  • self (Entity) –

Return type:

None

classmethod to_csv(objects, name, path=None, properties=None)

Exports MSTR objects to a csv file.

Optionally, saves only the object properties specified in the properties parameter.

Parameters:
  • objects (T | list[T]) – List of objects of the same type that

  • exported. (will be) –

  • name (str) – The name of the csv file ending with ‘.csv’

  • path (Optional[str], optional) – A path to the directory where the file will be saved. Defaults to None.

  • properties (Optional[list[str]], optional) – A list of object’s attribute names that should be included in the exported file. Defaults to None.

Raises:
  • TypeError – If objects is not of type T or list of type T

  • objects.

Return type:

None

to_dataframe()

Converts all properties of the object to a dataframe.

Returns:

A DataFrame object containing object properties.

Return type:

DataFrame

to_dict(camel_case=True, whitelist_keys=None, skip_private_keys=False)

Converts an object to a dictionary excluding object’s private properties. When converting the object to a dictionary, the object’s attributes become the dictionary’s keys and are in camel case by default Attribute values stored as objects are automatically converted to non-/ primitive data structures.

Parameters:
  • camel_case (bool, optional) – Set to True if attribute names should be converted from snake case to camel case. Defaults to True.

  • whitelist_keys (list[str], optional) – List of keys to include in the resulting dictionary. If None, all keys (except hidden ones) are included. Defaults to None.

  • skip_private_keys (bool, optional) – If True, skips private keys in final dict representation.

Returns:

A dictionary representation of object’s attributes and values.

By default, the dictionary keys are in camel case.

Return type:

dict

update_properties()

Save compatible local changes of the object attributes to the I-Server. Changes are retrieved from the self._altered_properties dictionary. After the process of update has finished, self._altered_properties is cleared. For this method to work properly, you must override the _alter_properties() method in a subclass.

Raises:

requests.HTTPError – If I-Server raises exception

Return type:

None

class mstrio.python_execution.script.Variable

Bases: Dictable

Script or Code Variable representation.

Base Variable shape from which script-type-specific Variables inherit.

answer(value=None, keep_personal_default=False, keep_global_default=False)

Answer the Variable with the provided value (or a FlagKeepDefaultAnswer flag).

Parameters:
  • value (VariableValue | FlagKeepDefaultAnswer) – Value to answer the Variable with or a flag to keep default value from a Variable. Optional only if keep_default flag is provided.

  • keep_personal_default (bool) – Whether to keep the personal default value from Variable as its answer. Defaults to False. If set to True, value parameter cannot be provided.

  • keep_global_default (bool) – Whether to keep the global default value from Variable as its answer. Defaults to False. If set to True, value parameter cannot be provided.

Returns:

Created answer for the Variable or a

FlagKeepDefaultAnswer flag.

Return type:

VariableAnswer

classmethod bulk_from_dict(source_list, connection=None, to_snake_case=True, with_missing_value=False)

Creates multiple objects from a list of dictionaries. For each dictionary provided the keys in camel case are changed to object’s attribute names (by default in snake case) and dict values are composed to their proper data types such as Enums, list of Enums etc. as specified in the object’s _FROM_DICT_MAP.

Parameters:
  • cls (T) – Class (type) of the objects that should be created.

  • source_list (List[Dict[str, Any]]) – A list of dictionaries from which the objects will be constructed.

  • connection (Connection, optional) – A MSTR Connection object. Defaults to None.

  • to_snake_case (bool, optional) – Set to True if attribute names should be converted from camel case to snake case. Defaults to True.

  • with_missing_value (bool) – (bool, optional): If True, class attributes possible to fetch and missing in source will be set as MissingValue objects.

Returns:

A list of objects of type T.

Return type:

T

classmethod from_dict(*args, **kwargs)

Creates an object from a dictionary. The dictionary’s keys in camel case are changed to object’s attribute names (by default in snake case) and dict values are composed to their proper data types such as Enums, list of Enums etc. as specified in _FROM_DICT_MAP.

Parameters:
  • cls (T) – Class (type) of an object that should be created.

  • source (Dict[str, Any]) – A dictionary from which an object will be constructed.

  • connection (Connection, optional) – A MSTR Connection object. Defaults to None.

  • to_snake_case (bool, optional) – Set to True if attribute names should be converted from camel case to snake case. Defaults to True.

  • with_missing_value – (bool, optional): If True, class attributes possible to fetch and missing in source will be set as MissingValue objects.

Returns:

An object of type T.

Return type:

T

get_answer_as_dict()

Generate to_dict representation for REST execution request for Script class, where Script exists and have Variables definition stored in its metadata and we just need to provide actual answers.

Note

This method assumes validation of the answer was already done.

Returns:

Dictionary representation of the Variable’s Answer.

Return type:

dict

get_answer_as_dict_for_non_script_run()

Generate to_dict representation for REST execution request for Code class, where Script does not exist and full variable representation is required, non-prompted.

It basically merges Variable definition and its Answer into one dict.

Note

This method assumes validation of the answer was already done.

Returns:

Dictionary representation of the Variable for non-Script run.

Return type:

dict

classmethod get_variable_by_identifier(variables, id_or_name)

Find Variable in the provided list by its ID or name.

Parameters:
  • variables (list[Variable | dict]) – List of Variables to search in.

  • id_or_name (str) – ID or name of the Variable to find.

Returns:

Found Variable or None if not found.

Return type:

Variable | dict | None

is_answered()

Check whether the Variable has a valid answer.

Returns:

True if the Variable is properly answered, False otherwise.

Return type:

bool

to_dict(camel_case=True, whitelist_keys=None, skip_private_keys=False)

Converts an object to a dictionary excluding object’s private properties. When converting the object to a dictionary, the object’s attributes become the dictionary’s keys and are in camel case by default Attribute values stored as objects are automatically converted to non-/ primitive data structures.

Parameters:
  • camel_case (bool, optional) – Set to True if attribute names should be converted from snake case to camel case. Defaults to True.

  • whitelist_keys (list[str], optional) – List of keys to include in the resulting dictionary. If None, all keys (except hidden ones) are included. Defaults to None.

  • skip_private_keys (bool, optional) – If True, skips private keys in final dict representation.

Returns:

A dictionary representation of object’s attributes and values.

By default, the dictionary keys are in camel case.

Return type:

dict

validate_whether_answered()

Validate whether the Variable is properly answered. Raises ScriptSetupError otherwise, with reasons.

Raises:

ScriptSetupError – When the Variable is not properly answered.

Return type:

None

desc: str | None = None
editable: bool | None = None
id: str | None = None
multiple: bool | None = None
name: str
nullable: bool | None = None
object_ref: SystemPrompt | dict | None = None
prompt: bool | None = None
required: bool | None = None
secret_value_input: bool | None = None
transaction_column: bool | None = None
type: VariableType | int = 1
value: str | int | float | datetime | date | list[str | int | float | datetime.datetime | datetime.date] | None = None
class mstrio.python_execution.script.VariableAnswer(source_variable: 'Variable', value: str | int | float | datetime.datetime | datetime.date | list[str | int | float | datetime.datetime | datetime.date] = None, secret_value_input: bool = True)

Bases: Variable

Parameters:
  • source_variable (Variable) –

  • value (str | int | float | datetime | date | list[str | int | float | datetime.datetime | datetime.date]) –

  • secret_value_input (bool) –

class For(id_or_name)

Bases: object

Helper method which exists solely to simplify answering prompted Variables in bulk.

This allows to be used within answers params in execute methods in Code or Script to be provided as follows:

` >>> ... >>> answers=[ >>>     VariableAnswer.For('var1').should_be('my-value'), >>>     VariableAnswer.For('var2').should_be_global_default, >>>     VariableAnswer.For('var3').should_be_personal_default, >>>     ... >>> ] >>> ... `

Parameters:

id_or_name (str) –

should_be(value)
Parameters:

value (VariableAnswer) –

Return type:

Callable[[list[Variable]], None]

answer(value=None, keep_personal_default=False, keep_global_default=False)

Answer the Variable with the provided value (or a FlagKeepDefaultAnswer flag).

Parameters:
  • value (VariableValue | FlagKeepDefaultAnswer) – Value to answer the Variable with or a flag to keep default value from a Variable. Optional only if keep_default flag is provided.

  • keep_personal_default (bool) – Whether to keep the personal default value from Variable as its answer. Defaults to False. If set to True, value parameter cannot be provided.

  • keep_global_default (bool) – Whether to keep the global default value from Variable as its answer. Defaults to False. If set to True, value parameter cannot be provided.

Returns:

Created answer for the Variable or a

FlagKeepDefaultAnswer flag.

Return type:

VariableAnswer

classmethod bulk_from_dict(source_list, connection=None, to_snake_case=True, with_missing_value=False)

Creates multiple objects from a list of dictionaries. For each dictionary provided the keys in camel case are changed to object’s attribute names (by default in snake case) and dict values are composed to their proper data types such as Enums, list of Enums etc. as specified in the object’s _FROM_DICT_MAP.

Parameters:
  • cls (T) – Class (type) of the objects that should be created.

  • source_list (List[Dict[str, Any]]) – A list of dictionaries from which the objects will be constructed.

  • connection (Connection, optional) – A MSTR Connection object. Defaults to None.

  • to_snake_case (bool, optional) – Set to True if attribute names should be converted from camel case to snake case. Defaults to True.

  • with_missing_value (bool) – (bool, optional): If True, class attributes possible to fetch and missing in source will be set as MissingValue objects.

Returns:

A list of objects of type T.

Return type:

T

classmethod from_dict(*args, **kwargs)

Creates an object from a dictionary. The dictionary’s keys in camel case are changed to object’s attribute names (by default in snake case) and dict values are composed to their proper data types such as Enums, list of Enums etc. as specified in _FROM_DICT_MAP.

Parameters:
  • cls (T) – Class (type) of an object that should be created.

  • source (Dict[str, Any]) – A dictionary from which an object will be constructed.

  • connection (Connection, optional) – A MSTR Connection object. Defaults to None.

  • to_snake_case (bool, optional) – Set to True if attribute names should be converted from camel case to snake case. Defaults to True.

  • with_missing_value – (bool, optional): If True, class attributes possible to fetch and missing in source will be set as MissingValue objects.

Returns:

An object of type T.

Return type:

T

get_answer_as_dict()

Generate to_dict representation for REST execution request for Script class, where Script exists and have Variables definition stored in its metadata and we just need to provide actual answers.

Note

This method assumes validation of the answer was already done.

Returns:

Dictionary representation of the Variable’s Answer.

Return type:

dict

get_answer_as_dict_for_non_script_run()

Generate to_dict representation for REST execution request for Code class, where Script does not exist and full variable representation is required, non-prompted.

It basically merges Variable definition and its Answer into one dict.

Note

This method assumes validation of the answer was already done.

Returns:

Dictionary representation of the Variable for non-Script run.

Return type:

dict

classmethod get_variable_by_identifier(variables, id_or_name)

Find Variable in the provided list by its ID or name.

Parameters:
  • variables (list[Variable | dict]) – List of Variables to search in.

  • id_or_name (str) – ID or name of the Variable to find.

Returns:

Found Variable or None if not found.

Return type:

Variable | dict | None

is_answered()

Check whether the Variable has a valid answer.

Returns:

True if the Variable is properly answered, False otherwise.

Return type:

bool

static is_keep_default_flag(flag)
Parameters:

flag (Any) –

Return type:

bool

classmethod is_of_valid_type(source_variable, answer_value)

Check whether the provided answer value is of valid type for the source variable.

Parameters:
  • source_variable (Variable) – Source Variable to check against.

  • answer_value (VariableValue) – Answer value to check.

Returns:

True if the provided answer value is of valid type for the

source variable.

Return type:

bool

is_valid()

Check whether the answer value is valid for the source variable.

Returns:

True if the answer value is valid for the source variable.

Return type:

bool

to_dict(camel_case=True)

Converts an object to a dictionary excluding object’s private properties. When converting the object to a dictionary, the object’s attributes become the dictionary’s keys and are in camel case by default Attribute values stored as objects are automatically converted to non-/ primitive data structures.

Parameters:
  • camel_case (bool, optional) – Set to True if attribute names should be converted from snake case to camel case. Defaults to True.

  • whitelist_keys (list[str], optional) – List of keys to include in the resulting dictionary. If None, all keys (except hidden ones) are included. Defaults to None.

  • skip_private_keys (bool, optional) – If True, skips private keys in final dict representation.

Returns:

A dictionary representation of object’s attributes and values.

By default, the dictionary keys are in camel case.

Return type:

dict

validate_whether_answered()

Validate whether the Variable is properly answered. Raises ScriptSetupError otherwise, with reasons.

Raises:

ScriptSetupError – When the Variable is not properly answered.

Return type:

None

desc: str | None = None
editable: bool | None = None
id: str | None = None
multiple: bool | None = None
name: str
nullable: bool | None = None
object_ref: SystemPrompt | dict | None = None
prompt: bool | None = None
required: bool | None = None
secret_value_input: bool = True
source_variable: Variable
transaction_column: bool | None = None
type: VariableType | int = 1
value: str | int | float | datetime | date | list[str | int | float | datetime.datetime | datetime.date] = None
class mstrio.python_execution.script.VariableDatasourceScript(name, id=None, type=VariableType.TEXT, desc=None, multiple=False, value=None)

Bases: Variable

Simple representation of a Variable for Datasource Scripts.

Parameters:
  • name (str) –

  • id (str | None) –

  • type (VariableType | int) –

  • desc (str | None) –

  • multiple (bool | None) –

  • value (str | int | float | datetime | date | list[str | int | float | datetime.datetime | datetime.date] | None) –

name

Variable name

Type:

str

id

Variable ID

Type:

str | None

type

Variable type

Type:

VariableType | int

desc

Variable description

Type:

str | None

multiple

Whether the variable is a list of values

Type:

bool | None

value

Variable default value, if any

Type:

str | int | float | datetime.datetime | datetime.date | list[str | int | float | datetime.datetime | datetime.date] | None

answer(value=None, keep_personal_default=False, keep_global_default=False)

Answer the Variable with the provided value (or a FlagKeepDefaultAnswer flag).

Parameters:
  • value (VariableValue | FlagKeepDefaultAnswer) – Value to answer the Variable with or a flag to keep default value from a Variable. Optional only if keep_default flag is provided.

  • keep_personal_default (bool) – Whether to keep the personal default value from Variable as its answer. Defaults to False. If set to True, value parameter cannot be provided.

  • keep_global_default (bool) – Whether to keep the global default value from Variable as its answer. Defaults to False. If set to True, value parameter cannot be provided.

Returns:

Created answer for the Variable or a

FlagKeepDefaultAnswer flag.

Return type:

VariableAnswer

classmethod bulk_from_dict(source_list, connection=None, to_snake_case=True, with_missing_value=False)

Creates multiple objects from a list of dictionaries. For each dictionary provided the keys in camel case are changed to object’s attribute names (by default in snake case) and dict values are composed to their proper data types such as Enums, list of Enums etc. as specified in the object’s _FROM_DICT_MAP.

Parameters:
  • cls (T) – Class (type) of the objects that should be created.

  • source_list (List[Dict[str, Any]]) – A list of dictionaries from which the objects will be constructed.

  • connection (Connection, optional) – A MSTR Connection object. Defaults to None.

  • to_snake_case (bool, optional) – Set to True if attribute names should be converted from camel case to snake case. Defaults to True.

  • with_missing_value (bool) – (bool, optional): If True, class attributes possible to fetch and missing in source will be set as MissingValue objects.

Returns:

A list of objects of type T.

Return type:

T

classmethod from_dict(*args, **kwargs)

Creates an object from a dictionary. The dictionary’s keys in camel case are changed to object’s attribute names (by default in snake case) and dict values are composed to their proper data types such as Enums, list of Enums etc. as specified in _FROM_DICT_MAP.

Parameters:
  • cls (T) – Class (type) of an object that should be created.

  • source (Dict[str, Any]) – A dictionary from which an object will be constructed.

  • connection (Connection, optional) – A MSTR Connection object. Defaults to None.

  • to_snake_case (bool, optional) – Set to True if attribute names should be converted from camel case to snake case. Defaults to True.

  • with_missing_value – (bool, optional): If True, class attributes possible to fetch and missing in source will be set as MissingValue objects.

Returns:

An object of type T.

Return type:

T

get_answer_as_dict()

Generate to_dict representation for REST execution request for Script class, where Script exists and have Variables definition stored in its metadata and we just need to provide actual answers.

Note

This method assumes validation of the answer was already done.

Returns:

Dictionary representation of the Variable’s Answer.

Return type:

dict

get_answer_as_dict_for_non_script_run()

Generate to_dict representation for REST execution request for Code class, where Script does not exist and full variable representation is required, non-prompted.

It basically merges Variable definition and its Answer into one dict.

Note

This method assumes validation of the answer was already done.

Returns:

Dictionary representation of the Variable for non-Script run.

Return type:

dict

classmethod get_variable_by_identifier(variables, id_or_name)

Find Variable in the provided list by its ID or name.

Parameters:
  • variables (list[Variable | dict]) – List of Variables to search in.

  • id_or_name (str) – ID or name of the Variable to find.

Returns:

Found Variable or None if not found.

Return type:

Variable | dict | None

is_answered()

Check whether the Variable has a valid answer.

Returns:

True if the Variable is properly answered, False otherwise.

Return type:

bool

to_dict(camel_case=True, whitelist_keys=None, skip_private_keys=False)

Converts an object to a dictionary excluding object’s private properties. When converting the object to a dictionary, the object’s attributes become the dictionary’s keys and are in camel case by default Attribute values stored as objects are automatically converted to non-/ primitive data structures.

Parameters:
  • camel_case (bool, optional) – Set to True if attribute names should be converted from snake case to camel case. Defaults to True.

  • whitelist_keys (list[str], optional) – List of keys to include in the resulting dictionary. If None, all keys (except hidden ones) are included. Defaults to None.

  • skip_private_keys (bool, optional) – If True, skips private keys in final dict representation.

Returns:

A dictionary representation of object’s attributes and values.

By default, the dictionary keys are in camel case.

Return type:

dict

validate_whether_answered()

Validate whether the Variable is properly answered. Raises ScriptSetupError otherwise, with reasons.

Raises:

ScriptSetupError – When the Variable is not properly answered.

Return type:

None

desc: str | None = None
editable: bool | None = None
id: str | None = None
multiple: bool | None = False
name: str
nullable: bool | None = None
object_ref: SystemPrompt | dict | None = None
prompt: bool | None = None
required: bool | None = None
secret_value_input: bool | None = None
transaction_column: bool | None = None
type: VariableType | int = 1
value: str | int | float | datetime | date | list[str | int | float | datetime.datetime | datetime.date] | None = None
class mstrio.python_execution.script.VariableStandardScript(name, id=None, type=VariableType.TEXT, desc=None, multiple=False, prompt=True, value=None, object_ref=None)

Bases: Variable

Simple representation of a Variable for Standard Scripts.

Parameters:
  • name (str) –

  • id (str | None) –

  • type (VariableType | int) –

  • desc (str | None) –

  • multiple (bool | None) –

  • prompt (bool | None) –

  • value (str | int | float | datetime | date | list[str | int | float | datetime.datetime | datetime.date] | None) –

  • object_ref (SystemPrompt | dict | None) –

name

Variable name

Type:

str

id

Variable ID

Type:

str | None

type

Variable type

Type:

VariableType | int

desc

Variable description

Type:

str | None

multiple

Whether the variable is a list of values

Type:

bool | None

prompt

Whether the variable prompts the user for input to be answered

Type:

bool | None

value

Variable default value, if any

Type:

str | int | float | datetime.datetime | datetime.date | list[str | int | float | datetime.datetime | datetime.date] | None

object_ref

For System Prompt variable, the System Prompt object referenced

Type:

SystemPrompt | dict | None

answer(value=None, keep_personal_default=False, keep_global_default=False)

Answer the Variable with the provided value (or a FlagKeepDefaultAnswer flag).

Parameters:
  • value (VariableValue | FlagKeepDefaultAnswer) – Value to answer the Variable with or a flag to keep default value from a Variable. Optional only if keep_default flag is provided.

  • keep_personal_default (bool) – Whether to keep the personal default value from Variable as its answer. Defaults to False. If set to True, value parameter cannot be provided.

  • keep_global_default (bool) – Whether to keep the global default value from Variable as its answer. Defaults to False. If set to True, value parameter cannot be provided.

Returns:

Created answer for the Variable or a

FlagKeepDefaultAnswer flag.

Return type:

VariableAnswer

classmethod bulk_from_dict(source_list, connection=None, to_snake_case=True, with_missing_value=False)

Creates multiple objects from a list of dictionaries. For each dictionary provided the keys in camel case are changed to object’s attribute names (by default in snake case) and dict values are composed to their proper data types such as Enums, list of Enums etc. as specified in the object’s _FROM_DICT_MAP.

Parameters:
  • cls (T) – Class (type) of the objects that should be created.

  • source_list (List[Dict[str, Any]]) – A list of dictionaries from which the objects will be constructed.

  • connection (Connection, optional) – A MSTR Connection object. Defaults to None.

  • to_snake_case (bool, optional) – Set to True if attribute names should be converted from camel case to snake case. Defaults to True.

  • with_missing_value (bool) – (bool, optional): If True, class attributes possible to fetch and missing in source will be set as MissingValue objects.

Returns:

A list of objects of type T.

Return type:

T

classmethod from_dict(*args, **kwargs)

Creates an object from a dictionary. The dictionary’s keys in camel case are changed to object’s attribute names (by default in snake case) and dict values are composed to their proper data types such as Enums, list of Enums etc. as specified in _FROM_DICT_MAP.

Parameters:
  • cls (T) – Class (type) of an object that should be created.

  • source (Dict[str, Any]) – A dictionary from which an object will be constructed.

  • connection (Connection, optional) – A MSTR Connection object. Defaults to None.

  • to_snake_case (bool, optional) – Set to True if attribute names should be converted from camel case to snake case. Defaults to True.

  • with_missing_value – (bool, optional): If True, class attributes possible to fetch and missing in source will be set as MissingValue objects.

Returns:

An object of type T.

Return type:

T

get_answer_as_dict()

Generate to_dict representation for REST execution request for Script class, where Script exists and have Variables definition stored in its metadata and we just need to provide actual answers.

Note

This method assumes validation of the answer was already done.

Returns:

Dictionary representation of the Variable’s Answer.

Return type:

dict

get_answer_as_dict_for_non_script_run()

Generate to_dict representation for REST execution request for Code class, where Script does not exist and full variable representation is required, non-prompted.

It basically merges Variable definition and its Answer into one dict.

Note

This method assumes validation of the answer was already done.

Returns:

Dictionary representation of the Variable for non-Script run.

Return type:

dict

classmethod get_variable_by_identifier(variables, id_or_name)

Find Variable in the provided list by its ID or name.

Parameters:
  • variables (list[Variable | dict]) – List of Variables to search in.

  • id_or_name (str) – ID or name of the Variable to find.

Returns:

Found Variable or None if not found.

Return type:

Variable | dict | None

is_answered()

Check whether the Variable has a valid answer.

Returns:

True if the Variable is properly answered, False otherwise.

Return type:

bool

to_dict(camel_case=True, whitelist_keys=None, skip_private_keys=False)

Converts an object to a dictionary excluding object’s private properties. When converting the object to a dictionary, the object’s attributes become the dictionary’s keys and are in camel case by default Attribute values stored as objects are automatically converted to non-/ primitive data structures.

Parameters:
  • camel_case (bool, optional) – Set to True if attribute names should be converted from snake case to camel case. Defaults to True.

  • whitelist_keys (list[str], optional) – List of keys to include in the resulting dictionary. If None, all keys (except hidden ones) are included. Defaults to None.

  • skip_private_keys (bool, optional) – If True, skips private keys in final dict representation.

Returns:

A dictionary representation of object’s attributes and values.

By default, the dictionary keys are in camel case.

Return type:

dict

validate_whether_answered()

Validate whether the Variable is properly answered. Raises ScriptSetupError otherwise, with reasons.

Raises:

ScriptSetupError – When the Variable is not properly answered.

Return type:

None

desc: str | None = None
editable: bool | None = None
id: str | None = None
multiple: bool | None = False
name: str
nullable: bool | None = None
object_ref: SystemPrompt | dict | None = None
prompt: bool | None = True
required: bool | None = None
secret_value_input: bool | None = None
transaction_column: bool | None = None
type: VariableType | int = 1
value: str | int | float | datetime | date | list[str | int | float | datetime.datetime | datetime.date] | None = None
class mstrio.python_execution.script.VariableTransactionScript(name, id=None, type=VariableType.TEXT, desc=None, multiple=False, value=None, prompt=False, object_ref=None, transaction_column=None, nullable=None, required=None, editable=None)

Bases: Variable

Simple representation of a Variable for Dashboard Transaction Scripts.

Parameters:
  • name (str) –

  • id (str | None) –

  • type (VariableType | int) –

  • desc (str | None) –

  • multiple (bool | None) –

  • value (str | int | float | datetime | date | list[str | int | float | datetime.datetime | datetime.date] | None) –

  • prompt (bool | None) –

  • object_ref (SystemPrompt | dict | None) –

  • transaction_column (bool | None) –

  • nullable (bool | None) –

  • required (bool | None) –

  • editable (bool | None) –

name

Variable name

Type:

str

id

Variable ID

Type:

str | None

type

Variable type

Type:

VariableType | int

desc

Variable description

Type:

str | None

multiple

Whether the variable is a list of values

Type:

bool | None

prompt

Whether the variable prompts the user for input to be answered

Type:

bool | None

object_ref

For System Prompt variable, the System Prompt object referenced

Type:

SystemPrompt | dict | None

transaction_column

Whether the variable represents transaction column

Type:

bool | None

nullable

Whether the transaction_column variable can contain null values

Type:

bool | None

required

Whether the transaction_column variable is required to be answered in transaction dashboard

Type:

bool | None

editable

Whether the value of transaction_column variable in the transaction dashboard can be edited (or only added or removed)

Type:

bool | None

answer(value=None, keep_personal_default=False, keep_global_default=False)

Answer the Variable with the provided value (or a FlagKeepDefaultAnswer flag).

Parameters:
  • value (VariableValue | FlagKeepDefaultAnswer) – Value to answer the Variable with or a flag to keep default value from a Variable. Optional only if keep_default flag is provided.

  • keep_personal_default (bool) – Whether to keep the personal default value from Variable as its answer. Defaults to False. If set to True, value parameter cannot be provided.

  • keep_global_default (bool) – Whether to keep the global default value from Variable as its answer. Defaults to False. If set to True, value parameter cannot be provided.

Returns:

Created answer for the Variable or a

FlagKeepDefaultAnswer flag.

Return type:

VariableAnswer

classmethod bulk_from_dict(source_list, connection=None, to_snake_case=True, with_missing_value=False)

Creates multiple objects from a list of dictionaries. For each dictionary provided the keys in camel case are changed to object’s attribute names (by default in snake case) and dict values are composed to their proper data types such as Enums, list of Enums etc. as specified in the object’s _FROM_DICT_MAP.

Parameters:
  • cls (T) – Class (type) of the objects that should be created.

  • source_list (List[Dict[str, Any]]) – A list of dictionaries from which the objects will be constructed.

  • connection (Connection, optional) – A MSTR Connection object. Defaults to None.

  • to_snake_case (bool, optional) – Set to True if attribute names should be converted from camel case to snake case. Defaults to True.

  • with_missing_value (bool) – (bool, optional): If True, class attributes possible to fetch and missing in source will be set as MissingValue objects.

Returns:

A list of objects of type T.

Return type:

T

classmethod from_dict(*args, **kwargs)

Creates an object from a dictionary. The dictionary’s keys in camel case are changed to object’s attribute names (by default in snake case) and dict values are composed to their proper data types such as Enums, list of Enums etc. as specified in _FROM_DICT_MAP.

Parameters:
  • cls (T) – Class (type) of an object that should be created.

  • source (Dict[str, Any]) – A dictionary from which an object will be constructed.

  • connection (Connection, optional) – A MSTR Connection object. Defaults to None.

  • to_snake_case (bool, optional) – Set to True if attribute names should be converted from camel case to snake case. Defaults to True.

  • with_missing_value – (bool, optional): If True, class attributes possible to fetch and missing in source will be set as MissingValue objects.

Returns:

An object of type T.

Return type:

T

get_answer_as_dict()

Generate to_dict representation for REST execution request for Script class, where Script exists and have Variables definition stored in its metadata and we just need to provide actual answers.

Note

This method assumes validation of the answer was already done.

Returns:

Dictionary representation of the Variable’s Answer.

Return type:

dict

get_answer_as_dict_for_non_script_run()

Generate to_dict representation for REST execution request for Code class, where Script does not exist and full variable representation is required, non-prompted.

It basically merges Variable definition and its Answer into one dict.

Note

This method assumes validation of the answer was already done.

Returns:

Dictionary representation of the Variable for non-Script run.

Return type:

dict

classmethod get_variable_by_identifier(variables, id_or_name)

Find Variable in the provided list by its ID or name.

Parameters:
  • variables (list[Variable | dict]) – List of Variables to search in.

  • id_or_name (str) – ID or name of the Variable to find.

Returns:

Found Variable or None if not found.

Return type:

Variable | dict | None

is_answered()

Check whether the Variable has a valid answer.

Returns:

True if the Variable is properly answered, False otherwise.

Return type:

bool

to_dict(camel_case=True, whitelist_keys=None, skip_private_keys=False)

Converts an object to a dictionary excluding object’s private properties. When converting the object to a dictionary, the object’s attributes become the dictionary’s keys and are in camel case by default Attribute values stored as objects are automatically converted to non-/ primitive data structures.

Parameters:
  • camel_case (bool, optional) – Set to True if attribute names should be converted from snake case to camel case. Defaults to True.

  • whitelist_keys (list[str], optional) – List of keys to include in the resulting dictionary. If None, all keys (except hidden ones) are included. Defaults to None.

  • skip_private_keys (bool, optional) – If True, skips private keys in final dict representation.

Returns:

A dictionary representation of object’s attributes and values.

By default, the dictionary keys are in camel case.

Return type:

dict

validate_whether_answered()

Validate whether the Variable is properly answered. Raises ScriptSetupError otherwise, with reasons.

Raises:

ScriptSetupError – When the Variable is not properly answered.

Return type:

None

desc: str | None = None
editable: bool | None = None
id: str | None = None
multiple: bool | None = False
name: str
nullable: bool | None = None
object_ref: SystemPrompt | dict | None = None
prompt: bool | None = False
required: bool | None = None
secret_value_input: bool | None = None
transaction_column: bool | None = None
type: VariableType | int = 1
value: str | int | float | datetime | date | list[str | int | float | datetime.datetime | datetime.date] | None = None
enum mstrio.python_execution.script.VariableType(value)

Bases: Enum

Valid values are as follows:

RESERVED = <VariableType.RESERVED: 0>
TEXT = <VariableType.TEXT: 1>
NUMERICAL = <VariableType.NUMERICAL: 2>
DATE = <VariableType.DATE: 3>
SECRET = <VariableType.SECRET: 4>
DATETIME = <VariableType.DATETIME: 5>
SYSTEM_PROMPT = <VariableType.SYSTEM_PROMPT: 4106>
TXN_ROW_PROVENANCE = <VariableType.TXN_ROW_PROVENANCE: 32769>
mstrio.python_execution.script.list_scripts(connection, name=None, search_pattern=SearchPattern.CONTAINS, project=None, project_id=None, project_name=None, to_dictionary=False, limit=None, folder=None, folder_id=None, folder_name=None, folder_path=None, **filters)

Get a list of scripts.

Parameters:
  • connection (Connection) – Strategy connection object returned by connection.Connection().

  • name (str, optional) – Name or part of the name of the Script.

  • search_pattern (SearchPattern | int, optional) – Search pattern for finding the Script by name. Defaults to SearchPattern.CONTAINS.

  • project (Project | str, optional) – Project object or ID or name specifying the project. May be used instead of project_id or project_name.

  • project_id (str, optional) – Project ID

  • project_name (str, optional) – Project name

  • to_dictionary (bool, optional) – If True returns dicts, by default (False) returns Script objects

  • limit (integer, optional) – limit the number of elements returned. If None all object are returned.

  • folder (Folder | tuple | list | str, optional) – Folder object or ID or name or path specifying the folder. May be used instead of folder_id, folder_name or folder_path.

  • folder_id (str, optional) – ID of a folder.

  • folder_name (str, optional) – Name of a folder.

  • folder_path (str, optional) –

    Path of the folder. The path has to be provided in the following format:

    if it’s inside of a project, start with a Project Name:

    /MicroStrategy Tutorial/Public Objects/Metrics

    if it’s a root folder, start with CASTOR_SERVER_CONFIGURATION:

    /CASTOR_SERVER_CONFIGURATION/Users

  • **filters – Available filter parameters: [‘id’, ‘description, ‘owner’, ‘date_created’, ‘date_modified’, ‘version’, ‘acg’]

Returns:

List of scripts as dicts or as Script objects.

Return type:

list[dict] | list[Script]