mstrio.project_objects.datasets package¶
Submodules¶
mstrio.project_objects.datasets.cube module¶
- class mstrio.project_objects.datasets.cube.CubeStates(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)¶
Bases:
Enum
- ACTIVE = 2¶
- DIRTY = 16¶
- DIRTY_INFO = 8¶
- FOREIGN = 2048¶
- IMPORTED = 1024¶
- LOADED = 32¶
- LOAD_PENDING = 128¶
- PENDING_FOR_ENGINE = 512¶
- PERSISTED = 4¶
- PROCESSING = 1¶
- READY = 64¶
- RESERVED = 0¶
- UNKNOWN1 = 4096¶
- UNKNOWN2 = 8192¶
- UNKNOWN3 = 16384¶
- UNLOAD_PENDING = 256¶
- classmethod show_status(status: int) list[str] ¶
Show states of a cube calculated from numerical value of its state. Additionally list of those states’ names is returned.
- Parameters:
status (integer) – numerical value of cube’s status
- Returns:
List with names of cube’s states.
- mstrio.project_objects.datasets.cube.list_all_cubes(connection: Connection, name: Optional[str] = None, search_pattern: mstrio.object_management.search_enums.SearchPattern | int = SearchPattern.CONTAINS, project_id: Optional[str] = None, project_name: Optional[str] = None, to_dictionary: bool = False, limit: Optional[int] = None, **filters) list['OlapCube', 'SuperCube'] | list[dict] ¶
Get list of Cube objects (OlapCube or SuperCube) or dicts with them. Optionally filter cubes by specifying ‘name’.
Optionally use to_dictionary to choose output format.
- Wildcards available for ‘name’:
? - any character * - 0 or more of any characters e.g. name = ?onny will return Sonny and Tonny
Specify either project_id or project_name. When project_id is provided (not None), project_name is omitted.
Note
When project_id is None and project_name is None, then its value is overwritten by project_id from connection object.
- Parameters:
connection – MicroStrategy connection object returned by connection.Connection()
name (string, optional) – value the search pattern is set to, which will be applied to the names of cubes being searched
search_pattern (SearchPattern enum or int, optional) – pattern to search for, such as Begin With or Contains. Possible values are available in ENUM mstrio.object_management.SearchPattern. Default value is BEGIN WITH (4).
project_id (string, optional) – Project ID
project_name (str, optional) – Project name
to_dictionary (bool, optional) – If True returns dict, by default (False) returns SuperCube/OlapCube objects
limit (integer, optional) – limit the number of elements returned. If None all object are returned.
**filters – Available filter parameters: [‘id’, ‘name’, ‘type’, ‘subtype’, ‘date_created’, ‘date_modified’, ‘version’, ‘owner’, ‘ext_type’, ‘view_media’, ‘certified_info’]
- Returns:
list with OlapCubes and SuperCubes or list of dictionaries
- mstrio.project_objects.datasets.cube.load_cube(connection: Connection, cube_id: Optional[str] = None, cube_name: Optional[str] = None, folder_id: Optional[str] = None, instance_id: Optional[str] = None) OlapCube | SuperCube | list[OlapCube, SuperCube] ¶
Load single cube specified by either ‘cube_id’ or both ‘cube_name’ and ‘folder_id’.
It is also possible to load cube by providing only cube_name, but in that case we may retrieve more than one cube as cube’s name is unique only within a folder.
instance_id is used only when a single cube is retrieved.
- Parameters:
connection – MicroStrategy connection object returned by connection.Connection()
cube_id (string, optional) – ID of cube
cube_name (string, optional) – name of cube
folder_id (string, optional) – ID of folder in which the cube is stored
instance_id (str, optional) – Identifier of an instance if cube instance has been already initialized. Will be used if only one cube is found. None by default.
- Returns:
object of type OlapCube or SuperCube based on the subtype of a cube returned from metadata.
- Raises:
ValueError when neither cube_id nor cube_name are provided. –
mstrio.project_objects.datasets.cube_cache module¶
- class mstrio.project_objects.datasets.cube_cache.CubeCache(connection: Connection, cache_id: str, cube_cache_dict: Optional[dict] = None)¶
Bases:
Cache
Manage cube cache.
- activate()¶
Activate cube cache.
- deactivate()¶
Deactivate cube cache.
- delete(force: bool = False)¶
Delete cube cache.
- Parameters:
force – If True, then no additional prompt will be shown before deleting CubeCache.
- Returns:
True for success. False otherwise.
- fetch()¶
- classmethod from_dict(connection: Connection, caches: list[dict]) list['CubeCache'] ¶
- get_manipulation_status(manipulation_id: str) dict ¶
Get manipulation status of cube cache.
- list_properties()¶
List properties for cube cache.
- load()¶
Load cache.
- unload()¶
Unload cache.
- mstrio.project_objects.datasets.cube_cache.delete_cube_cache(connection: Connection, id: str, force: bool = False)¶
Delete single cube cache.
- Parameters:
connection – MicroStrategy connection object returned by connection.Connection().
id (string) – cube cache ID
force (bool, optional) – If True, then no additional prompt will be shown before deleting caches for given cube. Default is False.
- Returns:
True for success. False otherwise.
- mstrio.project_objects.datasets.cube_cache.delete_cube_caches(connection: Connection, loaded: bool = False, force: bool = False, nodes: Optional[Union[list[str], str]] = None, cube_id: Optional[str] = None, db_connection_id: Optional[str] = None) Optional[dict] ¶
Delete all cube caches on a given node.
Optionally it is possible to specify for which cube or for which database connection caches will be deleted. It is also possible to delete only loaded caches.
You can specify from which nodes caches will be deleted. If nodes are None then all nodes are retrieved from cluster.
- Parameters:
connection – MicroStrategy connection object returned by connection.Connection().
nodes (list of strings or string, optional) – names of nodes from which caches will be deleted. By default it equals None and in that case all nodes names are loaded from the cluster.
cube_id (string, optional) – When provided, only caches for the cube with given ID will be deleted (if any).
db_connection_id (string, optional) – When provided, only caches for the database connection with given ID will be deleted (if any).
loaded (bool, optional) – If True then only loaded caches will be deleted. Otherwise all cubes will be returned.
force (bool, optional) – If True, then no additional prompt will be shown before deleting caches for given cube. Default is False.
- Returns:
‘succeeded’ - list with IDs of caches which were deleted
’failed’ - list with IDS of caches which were not deleted
or None when user doesn’t agree for deletion when prompted
- Return type:
Dictionary with two keys
- mstrio.project_objects.datasets.cube_cache.list_cube_caches(connection: Connection, nodes: Optional[Union[list[str], str]] = None, cube_id: Optional[str] = None, loaded: Optional[bool] = False, db_connection_id: Optional[str] = None, project_ids: Optional[list[str]] = None, to_dictionary: Optional[bool] = False, limit: Optional[int] = None) list['CubeCache'] | list[dict] ¶
List cube caches. You can filter them by cube (cube_id), database connection (db_connection_id) and projects (project_ids). You can also obtain only loaded caches (loaded=True).
You can specify from which nodes caches will be retrieved. If nodes are None then all nodes are retrieved from the cluster.
- Parameters:
connection – MicroStrategy connection object returned by connection.Connection().
nodes (list of strings or string, optional) – names of nodes on which caches will be searched. By default it equals None and in that case all nodes’ names are loaded from the cluster.
cube_id (string, optional) – When provided, only caches for the cube with given ID will be returned (if any).
loaded (bool, optional) – If True then only loaded caches will be retrieved. Otherwise all cubes will be returned.
db_connection_id (string, optional) – When provided, only caches for the database connection with given ID will be returned (if any).
project_ids (list of string, optional) – When provided only caches for projects with given IDs will be returned (if any).
to_dictionary (bool, optional) – If True returns dict, by default (False) returns CubeCache objects
limit (integer, optional) – Cut-off value for the number of objects returned. Default value is None which means no limit.
- Returns:
List of CubeCache objects when parameter to_dictionary is set to False (default value) or list of dictionaries otherwise.
mstrio.project_objects.datasets.olap_cube module¶
- class mstrio.project_objects.datasets.olap_cube.OlapCube(connection: Connection, id: str, name: Optional[str] = None, instance_id: Optional[str] = None, parallel: bool = True, progress_bar: bool = True)¶
Bases:
_Cube
Manage single table cube - according to EnumDSSXMLObjectSubTypes its subtype is 776 (DssXmlSubTypeReportCube). It inherits all properties from Cube.
- connection¶
MicroStrategy connection object returned by connection.Connection().
- id¶
Identifier of a pre-existing cube.
- instance_id¶
Identifier of a cube instance if already initialized, None by default.
- Type:
str
- name¶
name of the OlapCube
- size¶
size of cube
- Type:
integer
- status¶
status of cube
- Type:
integer
- path¶
full path of the cube on environment
- Type:
string
- owner_id¶
ID of cube’s owner
- Type:
string
- attributes¶
all attributes of cube
- Type:
list
- metrics¶
all metrics of cube
- Type:
list
- attr_elements¶
all attributes elements of cube
- Type:
list
- selected_attributes¶
IDs of filtered attributes
- Type:
list
- selected_metrics¶
IDs of filtered metrics
- Type:
list
- selected_attr_elements¶
IDs of filtered attribute elements
- Type:
list
- dataframe¶
content of a cube extracted into a Pandas DataFrame
- Type:
object
- table_definition¶
- classmethod available_attribute_forms(connection: Connection, basic_info_only: bool = True, to_dataframe: bool = False) list[dict] | list[pandas.core.frame.DataFrame] ¶
Get all attribute forms available on I-Server.
- Parameters:
connection – MicroStrategy connection object returned by connection.Connection()
basic_info_only (boolean, optional) – When True (default value) only values of id, name and type will be returned for each attribute form. When False, then all properties of each attribute form will be returned.
to_dataframe – When False (default value) then attribute forms are returned as a list of dictionaries. When True then attribute forms are returned as Pandas ‘DataFrame’.
- Returns:
List of attribute forms or attribute forms as Pandas DataFrame.
- classmethod available_attributes(connection: Connection, basic_info_only: bool = True, to_dataframe: bool = False) list[dict] | list[pandas.core.frame.DataFrame] ¶
Get all attributes available on I-Server.
- Parameters:
connection – MicroStrategy connection object returned by connection.Connection()
basic_info_only (boolean, optional) – When True (default value) only values of id, name and type will be returned for each attribute. When False, then all properties of each attribute will be returned.
to_dataframe – When False (default value) then attributes are returned as a list of dictionaries. When True then attributes are returned as Pandas ‘DataFrame’.
- Returns:
List of attributes or attributes as Pandas DataFrame.
- classmethod available_metrics(connection: Connection, basic_info_only: bool = True, to_dataframe: bool = False) list[dict] | list[pandas.core.frame.DataFrame] ¶
Get all metrics available on I-Server.
- Parameters:
connection – MicroStrategy connection object returned by connection.Connection()
basic_info_only (boolean, optional) – When True (default value) only values of id, name and type will be returned for each metric. When False, then all properties of each metric will be returned.
to_dataframe – When False (default value) then metrics are returned as a list of dictionaries. When True then metrics are returned as Pandas ‘DataFrame’.
- Returns:
List of attributes or attributes as Pandas DataFrame.
- classmethod create(connection: Connection, name: str, folder_id: str, description: Optional[str] = None, overwrite: bool = False, attributes: Optional[list[dict]] = None, metrics: Optional[list[dict]] = None) mstrio.project_objects.datasets.olap_cube.OlapCube | None ¶
Create an OLAP Cube by defining its name, description, destination folder, attributes and metrics.
- Parameters:
connection – MicroStrategy connection object returned by connection.Connection().
name (string) – OLAP Cube name.
folder_id (string) – Object ID of the folder where the cube should be saved.
description (string, optional) – OLAP Cube description
overwrite (boolean, optional) – Default value (False) not allow to overwrite the object with the same name.
attributes (list of dicts, optional) – list with dicts of attributes dicts to be in the working set of OLAP Cube. Each attribute dict should have keys: id, name and type. Attributes can be found with method OlapCube.available_attributes.
metrics (list of dicts, optional) – list with dicts of metrics to be in the working set of OLAP Cube. Each metric dict should have keys: id, name and type. Metrics can be found with method OlapCube.available_metrics.
- Returns:
Newly created OLAP Cube or None in case of wrongly provided attributes or metrics.
- Raises:
requests.exceptions.HTTPError –
to I-Server to create new OLAP Cube was not ok. –
- export_sql_view()¶
Export SQL View of an OLAP Cube.
- Returns:
SQL View of an OLAP Cube.
- publish() None ¶
Publish an OLAP Cube. Request to publish an OLAP Cube is an asynchronous operation, so the result of it can be seen after calling method refresh_status() inherited from Cube class.
- Returns:
A dictionary with two keys identifying task IDs.
- update(attributes: list[dict] = [], metrics: list[dict] = []) bool ¶
- Update an OLAP Cube. When Cube is unpublished, then it is possible to
add or remove attributes and metrics to/from its definition and rearrange existing one. When cube is published it is possible only to rearrange attributes and metrics existing in its definition. After this operation cube will have only attributes and metrics provided in parameters.
- Args:
- attributes(list of dicts, optional): list with dicts of attributes
dicts to be in the working set of OLAP Cube. Each attribute dict should have keys: id, name and type. Attributes can be found with method OlapCube.available_attributes.
- metrics(list of dicts, optional): list with dicts of metrics to be
in the working set of OLAP Cube. Each metric dict should have keys: id, name and type. Metrics can be found with method OlapCube.available_metrics.
- Returns:
True when update was successful. False otherwise.
- Raises:
requests.exceptions.HTTPError –
to I-Server to update new OLAP Cube was not ok. –
- mstrio.project_objects.datasets.olap_cube.list_olap_cubes(connection: Connection, name: Optional[str] = None, search_pattern: mstrio.object_management.search_enums.SearchPattern | int = SearchPattern.CONTAINS, project_id: Optional[str] = None, project_name: Optional[str] = None, to_dictionary: bool = False, limit: Optional[int] = None, **filters) list[mstrio.project_objects.datasets.olap_cube.OlapCube] | list[dict] ¶
Get list of OlapCube objects or dicts with them. Optionally filter cubes by specifying ‘name’.
Optionally use to_dictionary to choose output format.
- Wildcards available for ‘name’:
? - any character * - 0 or more of any characters e.g. name = ?onny will return Sonny and Tonny
Specify either project_id or project_name. When project_id is provided (not None), project_name is omitted.
Note
When project_id is None and project_name is None, then its value is overwritten by project_id from connection object.
- Parameters:
connection – MicroStrategy connection object returned by connection.Connection()
name (string, optional) – value the search pattern is set to, which will be applied to the names of olap cubes being searched
search_pattern (SearchPattern enum or int, optional) – pattern to search for, such as Begin With or Contains. Possible values are available in ENUM mstrio.object_management.SearchPattern. Default value is BEGIN WITH (4).
project_id (str, optional) – Project ID
project_name (str, optional) – Project name
to_dictionary (bool, optional) – If True returns dict, by default (False) returns OlapCube objects
limit (integer, optional) – limit the number of elements returned. If None all object are returned.
**filters – Available filter parameters: [‘id’, ‘name’, ‘type’, ‘subtype’, ‘date_created’, ‘date_modified’, ‘version’, ‘owner’, ‘ext_type’, ‘view_media’, ‘certified_info’]
- Returns:
list with OlapCubes or list of dictionaries
mstrio.project_objects.datasets.super_cube module¶
- class mstrio.project_objects.datasets.super_cube.SuperCube(connection: Connection, id: Optional[str] = None, name: Optional[str] = None, description: Optional[str] = None, instance_id: Optional[str] = None, progress_bar: bool = True, parallel: bool = True)¶
Bases:
_Cube
,CertifyMixin
Manage multiple table cube (MTDI aka Super Cube) - according to EnumDSSXMLObjectSubTypes its subtype is 779 (DssXmlSubTypeReportEmmaCube). It inherits all properties from Cube.
- connection¶
MicroStrategy connection object returned by connection.Connection().
- id¶
Identifier of a pre-existing cube.
- instance_id¶
Identifier of a cube instance if already initialized, None by default.
- Type:
str
- name¶
Name of the SuperCube.
- description¶
Description given to the SuperCube.
- id¶
Unique identifier for the super cube. Used to update a existing super cube or generated after creating a new super cube. (deprecated)
- upload_body¶
upload body of super cube
- Type:
string
- session_id¶
ID of session used for uploading and publishing super cube
- Type:
string
- size¶
size of cube
- Type:
integer
- status¶
status of cube
- Type:
integer
- path¶
full path of the cube on environment
- Type:
string
- owner_id¶
ID of cube’s owner
- Type:
string
- attributes¶
all attributes of cube
- Type:
list
- metrics¶
all metrics of cube
- Type:
list
- attr_elements¶
all attributes elements of cube
- Type:
list
- selected_attributes¶
IDs of filtered attributes
- Type:
list
- selected_metrics¶
IDs of filtered metrics
- Type:
list
- selected_attr_elements¶
IDs of filtered attribute elements
- Type:
list
- dataframe¶
content of a cube extracted into a Pandas DataFrame
- Type:
object
- table_definition¶
- add_table(name, data_frame, update_policy, to_metric=None, to_attribute=None)¶
Add a Pandas.DataFrame to a collection of tables which are later used to populate the MicroStrategy super cube with data.
- Parameters:
name (str) – Logical name of the table that is visible to users of the super cube in MicroStrategy.
data_frame (
pandas.DataFrame
) – Pandas DataFrame to add or update.update_policy (str) – Update operation to perform. One of ‘add’ (inserts new, unique rows), ‘update’ (updates data in existing rows and columns), ‘upsert’ (updates existing data and inserts new rows), or ‘replace’ (replaces the existing data with new data).
to_metric (optional,
list
of str) – By default, Python numeric data types are treated as metrics while character and date types are treated as attributes. For example, a column of integer-like strings (“1”, “2”, “3”) would, by default, be an attribute. If the intent is to format this data as a metric, provide the respective column name as a string in a list to the to_metric parameter.to_attribute (optional,
list
of str) – Logical opposite of to_metric. Helpful for formatting an integer-based row identifier as a primary key in the super cube.
- create(folder_id: Optional[str] = None, auto_upload: bool = True, auto_publish: bool = True, chunksize: int = 100000, force: bool = False) None ¶
Create a new super cube and initialize cube object after successful creation. This function does not return new super cube, but it updates object inplace.
- Parameters:
folder_id (str, optional) – ID of the shared folder in which the super cube will be created. If None, defaults to the user’s My Reports folder.
auto_upload (bool, optional) – If True, automatically uploads the data to the I-Server. If False, simply creates the super cube definition but does not upload data to it.
auto_publish (bool, optional) – If True, automatically publishes the data used to create the super cube definition. If False, simply creates the super cube but does not publish it. To publish the super cube, data has to be uploaded first.
chunksize (int, optional) – Number of rows to transmit to the I-Server with each request when uploading.
force (bool, optional) – If True, skip checking if a super cube already exist in the folder with the given name. Defaults to False.
- export_sql_view() str ¶
Export SQL View of a Super Cube.
- Returns:
SQL View of a Super Cube.
- publish() bool ¶
Publish the uploaded data to the selected super cube.
Note
A super cube can be published just once.
- Returns:
True if the data was published successfully, else False.
- publish_status()¶
Check the status of data that was uploaded to a super cube.
- Returns: status: The status of the publication process as a dictionary.
In the ‘status’ key, “1” denotes completion.
- remove_table(name)¶
Removes a table from a collection of tables which are later used to populate the MicroStrategy super cube with data.
- Note: this operation is executed locally and is used only to prepare
data before sending it to server. You can check current state of tables with property tables.
- Parameters:
name (str) – Logical name of the table that is visible to users of the super cube in MicroStrategy.
- reset_session()¶
Reset upload session.
- save_as(name: str, description: Optional[str] = None, folder_id: Optional[str] = None, table_name: Optional[str] = None) SuperCube ¶
Creates a new single-table cube with the data frame stored in the SuperCube instance SuperCube.dataframe.
- Parameters:
name (str) – Name of cube.
description (str) – Description of the cube.
folder_id (str, optional) – ID of the shared folder that the super cube should be created within. If None, defaults to the user’s My Reports folder.
table_name (str, optional) – Name of the table. If None (default), the first table name of the original cube will be used.
- update(chunksize: int = 100000, auto_publish: bool = True)¶
Updates a super cube with new data.
- Parameters:
chunksize (int, optional) – Number of rows to transmit to the server with each request.
auto_publish – If True, automatically publishes the data used to update the super cube definition to the super cube. If False, simply updates the super cube but does not publish it.
- static upload_status(connection: Connection, id: str, session_id: str)¶
Check the status of data that was uploaded to a super cube.
- Parameters:
connection (Optional[Connection]) – MicroStrategy connection object returned by connection.Connection().
id (Optional[str]) – Identifier of a pre-existing super cube.
session_id (Optional[str]) – Identifier of the server session used for collecting uploaded data.
- Returns:
- The status of the publication process as a dictionary. In
the ‘status’ key, “1” denotes completion.
- Return type:
status
- mstrio.project_objects.datasets.super_cube.list_super_cubes(connection: Connection, name: Optional[str] = None, search_pattern: mstrio.object_management.search_enums.SearchPattern | int = SearchPattern.CONTAINS, project_id: Optional[str] = None, project_name: Optional[str] = None, to_dictionary: bool = False, limit: Optional[int] = None, **filters) list[mstrio.project_objects.datasets.super_cube.SuperCube] | list[dict] ¶
Get list of SuperCube objects or dicts with them. Optionally filter cubes by specifying ‘name’.
Optionally use to_dictionary to choose output format.
- Wildcards available for ‘name’:
? - any character * - 0 or more of any characters e.g. name = ?onny will return Sonny and Tonny
Specify either project_id or project_name. When project_id is provided (not None), project_name is omitted.
Note
When project_id is None and project_name is None, then its value is overwritten by project_id from connection object.
- Parameters:
connection – MicroStrategy connection object returned by connection.Connection()
name (string, optional) – value the search pattern is set to, which will be applied to the names of super cubes being searched
search_pattern (SearchPattern enum or int, optional) – pattern to search for, such as Begin With or Contains. Possible values are available in ENUM mstrio.object_management.SearchPattern. Default value is BEGIN WITH (4).
project_id (string, optional) – Project ID
project_name (string, optional) – Project name
to_dictionary (bool, optional) – If True returns dict, by default (False) returns SuperCube objects
limit (integer, optional) – limit the number of elements returned. If None all object are returned.
**filters – Available filter parameters: [‘id’, ‘name’, ‘type’, ‘subtype’, ‘date_created’, ‘date_modified’, ‘version’, ‘owner’, ‘ext_type’, ‘view_media’, ‘certified_info’]
- Returns:
list with SuperCubes or list of dictionaries