atoti.query.session module

class atoti.query.session.QuerySession(url, *, auth=None, name=None)

Bases: atoti._base._base_session.BaseSession[atoti.query.cubes.QueryCubes]

Used to query an existing session.

Query sessions are considered immutable: the structure of their cubes is not expected to change.

property cubes

Cubes of the session.

Return type

QueryCubes

property name

Name of the session.

Return type

str

property port

Port of the session.

Return type

Optional[int]

query_mdx(mdx, *, keep_totals=False, timeout=30, **kwargs)

Execute an MDX query and return its result as a pandas DataFrame.

Parameters
  • mdx (str) – The MDX SELECT query to execute.

  • keep_totals (bool) – Whether the returned DataFrame should contain, if they are present in the query result, the grand total and subtotals.

  • timeout (int) – The query timeout in seconds.

  • keep_totals – Whether the resulting DataFrame should contain, if they are present in the query result, the grand total and subtotals. Totals can be useful but they make the DataFrame harder to work with since its index will have some empty values.

Example

An MDX query that would be displayed as this pivot table:

Country

Total Price.SUM

2018-01-01

2019-01-01

2019-01-02

2019-01-05

Price.SUM

Price.SUM

Price.SUM

Price.SUM

Total Country

2,280.00

840.00

1,860.00

810.00

770.00

China

760.00

410.00

350.00

France

1,800.00

480.00

500.00

400.00

420.00

India

760.00

360.00

400.00

UK

960.00

960.00

will return this DataFrame:

Date

Country

Price.SUM

2019-01-02

China

410.0

2019-01-05

China

350.0

2018-01-01

France

480.0

2019-01-01

France

500.0

2019-01-02

France

400.0

2019-01-05

France

420.0

2018-01-01

India

360.0

2019-01-01

India

400.0

2019-01-01

UK

960.0

Return type

QueryResult

property url

URL of the session.

Return type

str

visualize(name=None)

Display an atoti widget to explore the session interactively.

Note

This method requires the atoti-jupyterlab plugin.

The widget state will be stored in the cell metadata. This state should not have to be edited but, if desired, it can be found in JupyterLab by opening the “Notebook tools” sidebar and expanding the the “Advanced Tools” section.

Parameters

name (Optional[str]) – The name to give to the widget.