atoti.query package

Submodules

atoti.query.auth module

atoti.query.auth.Auth

Called with the URL of the request and returning the HTTP headers necessary to authenticate it.

alias of Callable[[str], Optional[Mapping[str, str]]]

atoti.query.cube module

class atoti.query.cube.QueryCube(name, hierarchies, measures, _session)

Bases: object

Query cube.

hierarchies: QueryHierarchies

Hierarchies of the cube.

property levels

Levels of the cube.

Return type

QueryLevels

measures: QueryMeasures

Measures of the cube.

name: str

Name of the cube.

query(*measures, levels=None, condition=None, scenario='Base', timeout=30, **kwargs)

Query the cube to get the value of some measures.

The value of the measures is given on all the members of the given levels.

Parameters
  • measures (QueryMeasure) – The measures to query. If None, all the measures are queried.

  • levels (Union[QueryLevel, Sequence[QueryLevel], None]) – The levels to split on. If None, the value of the measures at the top of the cube is returned.

  • condition (Union[LevelCondition, MultiCondition, None]) –

    The filtering condition. Only conditions on level equality with a string are supported. For instance:

    • lvl["Country"] == "France"

    • (lvl["Country"] == "USA") & (lvl["Currency"] == "USD")

  • scenario (str) – The scenario to query.

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

Return type

QueryResult

Returns

The resulting DataFrame.

atoti.query.cubes module

class atoti.query.cubes.QueryCubes(_data)

Bases: atoti._mappings.ImmutableMapping[str, atoti.query.cube.QueryCube]

Manage the query cubes.

get(k[, d]) → D[k] if k in D, else d. d defaults to None.
items() → a set-like object providing a view on D’s items
keys() → a set-like object providing a view on D’s keys
values() → an object providing a view on D’s values

atoti.query.hierarchies module

class atoti.query.hierarchies.QueryHierarchies(_data)

Bases: atoti._mappings.ImmutableMapping[str, atoti.query.hierarchy.QueryHierarchy]

Manage the query hierarchies.

get(k[, d]) → D[k] if k in D, else d. d defaults to None.
items() → a set-like object providing a view on D’s items
keys() → a set-like object providing a view on D’s keys
values() → an object providing a view on D’s values

atoti.query.hierarchy module

class atoti.query.hierarchy.QueryHierarchy(name, dimension, levels, slicing)

Bases: object

Hierarchy of a query cube.

dimension: str

Dimension of the hierarchy.

isin(*member_paths)

Return a condition to check that the hierarchy is on one of the given members.

Considering hierarchy_1 containing level_1 and level_2, hierarchy_1.isin((a, x), (b,)) is equivalent to ((level_1 == a) & (level_2 == x)) | (level_1 == b).

Example

Considering a “Geography” hierarchy containing two levels “Country” and “City”, and this measure:

measures["Price in USA/Paris and Germany"] = atoti.filter(
    measures["Price"],
    hierarchies["Geography"].isin(("USA", "Paris"), ("Germany", ))
)

The behavior is the following one:

Country

City

Price

measures[“Price in USA/Paris and Germany”]

France

Paris

200.0

Germany

Berlin

150.0

150.0

UK

London

240.0

USA

New York

270.0

USA

Paris

500.0

500.0

Parameters

members – One or more members expressed as tuples on which the hierarchy should be. Each element in a tuple corresponds to a level of the hierarchy, from the shallowest to the deepest.

Return type

HierarchyIsInCondition

levels: atoti._mappings.ImmutableMapping[str, atoti.query.level.QueryLevel]

Levels of the hierarchy.

name: str

Name of the hierarchy.

slicing: bool

Whether the hierarchy is slicing or not.

atoti.query.level module

class atoti.query.level.QueryLevel(name, dimension, hierarchy)

Bases: object

Level of a query cube.

dimension: str

Dimension of the level.

hierarchy: str

Hierarchy of the level.

isin(*members)

Return a condition to check that the level is on one of the given members.

lvl["x"].isin("a", "b") is equivalent to lvl["x"] == "a" OR lvl["x"] == "b".

Parameters

members (Any) – One or more members on which the level should be.

Example

>>> df = pd.DataFrame(
...     columns=["City", "Price"],
...     data=[
...         ("Berlin", 150.0),
...         ("London", 240.0),
...         ("New York", 270.0),
...         ("Paris", 200.0),
...     ],
... )
>>> store = session.read_pandas(df, keys=["City"], store_name="Cities")
>>> cube = session.create_cube(store)
>>> lvl, m = cube.levels, cube.measures
>>> m["Price.SUM in Berlin"] = tt.filter(
...     m["Price.SUM"], lvl["City"].isin("Berlin")
... )
>>> m["Price.SUM in London and Paris"] = tt.filter(
...     m["Price.SUM"], lvl["City"].isin("London", "Paris")
... )
>>> cube.query(
...     m["Price.SUM"],
...     m["Price.SUM in Berlin"],
...     m["Price.SUM in London and Paris"],
...     levels=lvl["City"],
... )
        Price.SUM Price.SUM in Berlin Price.SUM in London and Paris
City
Berlin      150.00              150.00                          <NA>
London      240.00                <NA>                        240.00
New York    270.00                <NA>                          <NA>
Paris       200.00                <NA>                        200.00
Return type

LevelIsInCondition

name: str

Name of the level.

atoti.query.levels module

class atoti.query.levels.QueryLevels(_hierarchies)

Bases: atoti._base_levels.BaseLevels[atoti.query.level.QueryLevel, atoti.query.hierarchies.QueryHierarchies]

Flat representation of all the levels in the cube.

get(k[, d]) → D[k] if k in D, else d. d defaults to None.
items() → a set-like object providing a view on D’s items
keys() → a set-like object providing a view on D’s keys
values() → an object providing a view on D’s values

atoti.query.measure module

class atoti.query.measure.QueryMeasure(name, visible, folder, formatter, description)

Bases: object

Measure of a query cube.

description: Optional[str]

Description of the measure.

folder: Optional[str]

Folder in which the measure is.

formatter: Optional[str]

Formatter of the measure.

name: str

Name of the measure.

visible: bool

Whether the measure is visible or not.

atoti.query.measures module

class atoti.query.measures.QueryMeasures(_data)

Bases: atoti._mappings.ImmutableMapping[str, atoti.query.measure.QueryMeasure]

Manage the query measures.

get(k[, d]) → D[k] if k in D, else d. d defaults to None.
items() → a set-like object providing a view on D’s items
keys() → a set-like object providing a view on D’s keys
values() → an object providing a view on D’s values

atoti.query.query_result module

class atoti.query.query_result.QueryResult(data=None, index=None, *, context=None, formatted_values, get_styler, mdx=None)

Bases: pandas.core.frame.DataFrame

Custom pandas DataFrame that can be converted to a widget by our JupyterLab extension.

property style

Return a Styler object.

If the DataFrame has not been changed in place since its creation, the returned object will follow the styling included in the cellset from which the DataFrame was converted.

Return type

Styler

atoti.query.session module

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

Bases: object

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, *, timeout=30, **kwargs)

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

Resulting cells representing totals are ignored, they will not be part of the returned DataFrame. Members for which all the measures are None are ignored too.

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

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

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

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.

Module contents

atoti.query.create_basic_authentication(username, password)

Create a basic authentication.

Return type

Callable[[str], Optional[Mapping[str, str]]]

atoti.query.create_token_authentication(token)

Create an authentication based on a Bearer token.

Parameters

token (str) – The token to use to authenticate, such as a JWT.

Return type

Callable[[str], Optional[Mapping[str, str]]]