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
-
measures
: QueryMeasures¶ Measures 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. IfNone
, all the measures are queried.levels (
Union
[QueryLevel
,Sequence
[QueryLevel
],None
]) – The levels to split on. IfNone
, 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
- Returns
The resulting DataFrame.
-
atoti.query.cubes module¶
-
class
atoti.query.cubes.
QueryCubes
(_data)¶ Bases:
atoti._mappings.ImmutableMapping
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
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.
-
isin
(*member_paths)¶ Return a condition to check that the hierarchy is on one of the given members.
Considering
hierarchy_1
containinglevel_1
andlevel_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.
-
atoti.query.level module¶
-
class
atoti.query.level.
QueryLevel
(name, dimension, hierarchy)¶ Bases:
object
Level of a query cube.
-
isin
(*members)¶ Return a condition to check that the level is on one of the given members.
levels["x"].isin("a", "b")
is equivalent tolevels["x"] == "a" OR levels["x"] == "b"
.Example
Considering this measure:
measures["Price in Paris and London"] = atoti.filter( measures["Price"], levels["City"].isin("Paris", "London") )
The behavior is the following one:
City
Price
measures[“Price in Paris and London”]
Paris
200.0
200.0
Berlin
150.0
London
240.0
240.0
New York
270.0
- Parameters
members (
Any
) – One or more members on which the level should be.- Return type
LevelIsInCondition
-
atoti.query.levels module¶
-
class
atoti.query.levels.
QueryLevels
(_hierarchies)¶ Bases:
atoti._base_levels.BaseLevels
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¶
atoti.query.measures module¶
-
class
atoti.query.measures.
QueryMeasures
(_data)¶ Bases:
atoti._mappings.ImmutableMapping
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
-
property
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
-
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
- Return type
-
visualize
(name=None)¶ Display an atoti widget to explore the session interactively.
Attention
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.
-
property