mstrio > connection

class mstrio.connection.Connection(base_url, username=None, password=None, project_name=None, project_id=None, login_mode=None, ssl_verify=True, certificate_path=None, proxies=None, identity_token=None, api_token=None, application_id=None, working_set=None, max_search=None, verbose=True)

Bases: object

Connect to and interact with the Strategy One environment.

Creates a connection object which is used in subsequent requests and manages the user’s connection with the Strategy One REST and Intelligence Servers. The connection is automatically renewed, or reconnected if server’s session associated with the connection expires due to inactivity.

Examples

>>> from mstrio import connection
>>>
>>> # connect to the environment and chosen project
>>> conn = connection.Connection(
>>>     base_url="https://demo.microstrategy.com/MicroStrategyLibrary",
>>>     username="username",
>>>     password="password",
>>>     project_name="MicroStrategy Tutorial"
>>> )
>>> # disconnect
>>> conn.close()
Parameters:
  • base_url (str) –

  • username (str | None) –

  • password (str | None) –

  • project_name (str | None) –

  • project_id (str | None) –

  • login_mode (int | LoginMode | None) –

  • ssl_verify (bool) –

  • certificate_path (str | None) –

  • proxies (dict | None) –

  • identity_token (str | None) –

  • api_token (str | None) –

  • application_id (str | Application | None) –

  • working_set (int | None) –

  • max_search (int | None) –

  • verbose (bool) –

base_url

URL of the Strategy One REST API server.

username

Username.

project_name

Name of the connected Strategy One Project.

project_id

Id of the connected Strategy One Project.

login_mode

Authentication mode. Standard = 1 (default), LDAP = 16 or API Token = 4096.

ssl_verify

If True (default), verifies the server’s SSL certificates with each request.

user_id

Id of the authenticated user

user_full_name

Full name of the authenticated user

user_initials

Initials of the authenticated user

iserver_version

Version of the I-Server

web_version

Version of the Web Server

token

authentication token

working_set

Number of report/document instances that are kept in memory on the server before the oldest instance is replaced.

Maximum number of concurrent searches.

timeout

time after the server’s session expires, in seconds

close()

Closes a connection with Strategy One REST API.

connect()

Authenticates the user and creates a new connection with the Intelligence Server.

If an active connection is detected, the session is renewed.

Return type:

None

delegate()

Delegates identity token to get authentication token and connect to Strategy One Intelligence Server.

delete(url=None, *, endpoint=None, **kwargs)

Sends a DELETE request.

get(url=None, *, endpoint=None, **kwargs)

Sends a GET request.

get_api_token()

Create new API token using existing authentication token.

Return type:

str

get_identity_token()

Create new identity token using existing authentication token.

Return type:

str

head(url=None, *, endpoint=None, **kwargs)

Sends a HEAD request.

classmethod is_run_in_workstation()

Check if the script is run in Workstation.

Returns:

True if the script is run in Workstation, False otherwise.

It may return None when gathering this info failed.

Return type:

bool

patch(url=None, *, endpoint=None, **kwargs)

Sends a PATCH request.

post(url=None, *, endpoint=None, **kwargs)

Sends a POST request.

put(url=None, *, endpoint=None, **kwargs)

Sends a PUT request.

renew()

Authenticates the user and creates a new connection with the Intelligence Server.

If an active connection is detected, the session is renewed.

Return type:

None

select_project(project_id=None, project_name=None)

Select project for the given connection based on project_id or project_name.

When both project_id and project_name are None, project selection is cleared. When both project_id and project_name are provided, project_name is ignored.

Parameters:
  • project_id (str | None) – id of project to select

  • project_name (str | None) – name of project to select

Raises:

ValueError – if project with given id or name does not exist

Return type:

None

status()

Checks if the session is still alive.

Raises:

HTTPError if I-Server behaves unexpectedly

Return type:

bool

validate_identity_token()

Validate the identity token.

Return type:

bool

enum mstrio.connection.LoginMode(value)

Bases: IntEnum

Member Type:

int

Valid values are as follows:

STANDARD = <LoginMode.STANDARD: 1>
ANONYMOUS = <LoginMode.ANONYMOUS: 8>
LDAP = <LoginMode.LDAP: 16>
API_TOKEN = <LoginMode.API_TOKEN: 4096>

The Enum and its members also have the following methods:

as_integer_ratio()

Return a pair of integers, whose ratio is equal to the original int.

The ratio is in lowest terms and has a positive denominator.

>>> (10).as_integer_ratio()
(10, 1)
>>> (-10).as_integer_ratio()
(-10, 1)
>>> (0).as_integer_ratio()
(0, 1)
bit_count()

Number of ones in the binary representation of the absolute value of self.

Also known as the population count.

>>> bin(13)
'0b1101'
>>> (13).bit_count()
3
bit_length()

Number of bits necessary to represent self in binary.

>>> bin(37)
'0b100101'
>>> (37).bit_length()
6
conjugate()

Returns self, the complex conjugate of any int.

from_bytes(byteorder='big', *, signed=False)

Return the integer represented by the given array of bytes.

bytes

Holds the array of bytes to convert. The argument must either support the buffer protocol or be an iterable object producing bytes. Bytes and bytearray are examples of built-in objects that support the buffer protocol.

byteorder

The byte order used to represent the integer. If byteorder is ‘big’, the most significant byte is at the beginning of the byte array. If byteorder is ‘little’, the most significant byte is at the end of the byte array. To request the native byte order of the host system, use sys.byteorder as the byte order value. Default is to use ‘big’.

signed

Indicates whether two’s complement is used to represent the integer.

is_integer()

Returns True. Exists for duck type compatibility with float.is_integer.

to_bytes(length=1, byteorder='big', *, signed=False)

Return an array of bytes representing an integer.

length

Length of bytes object to use. An OverflowError is raised if the integer is not representable with the given number of bytes. Default is length 1.

byteorder

The byte order used to represent the integer. If byteorder is ‘big’, the most significant byte is at the beginning of the byte array. If byteorder is ‘little’, the most significant byte is at the end of the byte array. To request the native byte order of the host system, use sys.byteorder as the byte order value. Default is to use ‘big’.

signed

Determines whether two’s complement is used to represent the integer. If signed is False and a negative integer is given, an OverflowError is raised.

denominator

the denominator of a rational number in lowest terms

imag

the imaginary part of a complex number

numerator

the numerator of a rational number in lowest terms

real

the real part of a complex number

mstrio.connection.get_connection(workstation_data, project_name=None, project_id=None, ssl_verify=False)

Connect to environment without providing user’s credentials.

It is possible to provide project_id or project_name to select project. When both project_id and project_name are None, project selection is cleared. When both project_id and project_name are provided, project_name is ignored. Project can be also selected later by calling method select_project on Connection object.

Note

ssl_verify is set to False by default just for the get_connection function as it is designed for usage inside Workstation. When ssl_verify is set to False, warning about missing certificate verification (InsecureRequestWarning) is disabled.

Parameters:
  • workstation_data (object) – object which is stored in a ‘workstationData’ variable within Workstation

  • project_name (str, optional) – name of project (aka project) to select

  • project_id (str, optional) – id of project (aka project) to select

  • ssl_verify (bool, optional) – If False (default), does not verify the server’s SSL certificates

Returns:

connection to I-Server or None is case of some error

Return type:

Connection | None