mstrio.project_objects.datasets package¶
Submodules¶
mstrio.project_objects.datasets.cube module¶
- class mstrio.project_objects.datasets.cube.CubeStates(value)¶
Bases:
enum.Enum
An enumeration.
- 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: mstrio.connection.Connection, name: Optional[str] = None, name_begins: Optional[str] = None, search_pattern: Union[mstrio.object_management.search_enums.SearchPattern, int] = SearchPattern.CONTAINS, project_id: Optional[str] = None, to_dictionary: bool = False, limit: Optional[int] = None, **filters) Union[List[Union[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_begins’:
? - any character * - 0 or more of any characters e.g. name_begins = ?onny will return Sonny and Tonny
- 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
name_begins (string, optional) – deprecated. Use name instead.
search_pattern (SearchPattern enum or int, optional) – pattern to search for, such as Begin With or Contains. Possible values are available in ENUM mstrio.browsing.SearchPattern. Default value is BEGIN WITH (4).
project_id (string, optional) – Project ID
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: mstrio.connection.Connection, cube_id: Optional[str] = None, cube_name: Optional[str] = None, folder_id: Optional[str] = None, instance_id: Optional[str] = None) Union[OlapCube, SuperCube, List[Union[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: dict = None)¶
Bases:
object
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()¶
Refresh cube cache properties by retrieving them from I-Server.
- classmethod from_dict(connection: Connection, caches: List[dict]) List[CubeCache] ¶
- get_manipulation_status(manipulation_id: str) Optional[dict] ¶
Get manipulation status of cube cache.
- list_properties()¶
List properties for cube cache.
- load()¶
Load cube cache.
- unload()¶
Unload cube 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, nodes: Union[List[str], str] = None, cube_id: str = None, db_connection_id: str = None, loaded: bool = False, force: bool = False) 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) Union[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: mstrio.connection.Connection, id: str, name: Optional[str] = None, instance_id: Optional[str] = None, parallel: bool = True, progress_bar: bool = True)¶
Bases:
mstrio.project_objects.datasets.cube._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: mstrio.connection.Connection, basic_info_only: bool = True, to_dataframe: bool = False) Union[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: mstrio.connection.Connection, basic_info_only: bool = True, to_dataframe: bool = False) Union[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: mstrio.connection.Connection, basic_info_only: bool = True, to_dataframe: bool = False) Union[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: mstrio.connection.Connection, name: str, folder_id: str, description: Optional[str] = None, overwrite: bool = False, attributes: List[dict] = [], metrics: List[dict] = []) Optional[mstrio.project_objects.datasets.olap_cube.OlapCube] ¶
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.
- 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: mstrio.connection.Connection, name: Optional[str] = None, name_begins: Optional[str] = None, search_pattern: Union[mstrio.object_management.search_enums.SearchPattern, int] = SearchPattern.CONTAINS, project_id: Optional[str] = None, to_dictionary: bool = False, limit: Optional[int] = None, **filters) Union[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_begins’:
? - any character * - 0 or more of any characters e.g. name_begins = ?onny will return Sonny and Tonny
- 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
name_begins (string, optional) – deprecated. Use name instead.
search_pattern (SearchPattern enum or int, optional) – pattern to search for, such as Begin With or Contains. Possible values are available in ENUM mstrio.browsing.SearchPattern. Default value is BEGIN WITH (4).
project_id (str, optional) – Project ID
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: mstrio.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:
mstrio.project_objects.datasets.cube._Cube
,mstrio.utils.entity.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) 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.
- 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
- The status of the publication process as a dictionary. In
the ‘status’ key, “1” denotes completion.
- Return type
status
- save_as(name: str, description: Optional[str] = None, folder_id: Optional[str] = None, table_name: Optional[str] = None) mstrio.project_objects.datasets.super_cube.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.
- upload_status(connection: mstrio.connection.Connection, id: str, session_id: str)¶
Check the status of data that was uploaded to a super cube.
- Parameters
connection – MicroStrategy connection object returned by connection.Connection().
id (str) – Identifier of a pre-existing super cube.
session_id (str) – Identifier of the server session used for collecting uploaded data.
- mstrio.project_objects.datasets.super_cube.list_super_cubes(connection: mstrio.connection.Connection, name: Optional[str] = None, name_begins: Optional[str] = None, search_pattern: Union[mstrio.object_management.search_enums.SearchPattern, int] = SearchPattern.CONTAINS, project_id: Optional[str] = None, to_dictionary: bool = False, limit: Optional[int] = None, **filters) Union[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_begins’:
? - any character * - 0 or more of any characters e.g. name_begins = ?onny will return Sonny and Tonny
- 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
name_begins (string, optional) – deprecated. Use name instead.
search_pattern (SearchPattern enum or int, optional) – pattern to search for, such as Begin With or Contains. Possible values are available in ENUM mstrio.browsing.SearchPattern. Default value is BEGIN WITH (4).
project_id (string, optional) – Project ID
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