atoti-client-limits 6.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,18 @@
1
+ Metadata-Version: 2.3
2
+ Name: atoti-client-limits
3
+ Version: 6.2.0
4
+ Summary: Code to interact with Atoti Limits
5
+ Keywords: atoti,limits
6
+ Author: ActiveViam
7
+ Author-email: ActiveViam <atoti-dev@activeviam.com>
8
+ Classifier: Development Status :: 4 - Beta
9
+ Classifier: License :: Free for non-commercial use
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Typing :: Typed
13
+ Requires-Dist: atoti-client==6.2.0
14
+ Requires-Dist: pydantic>=2.12.3
15
+ Requires-Python: >=3.12
16
+ Project-URL: Documentation, https://docs.activeviam.com/products/atoti/python-sdk/6.2.0/api/atoti_limits.html
17
+ Project-URL: Homepage, https://www.atoti.io
18
+ Project-URL: Issues, https://github.com/atoti/atoti/issues
@@ -0,0 +1,6 @@
1
+ atoti_limits/__init__.py,sha256=KETqC0AAZWIrba-mdEfGtKpvDCeYDwjbdj1wNPwq6d4,4365
2
+ atoti_limits/limits_config.py,sha256=F8TzzxTGfK6gSw8Zp3pO4PB5qepbZnnZO3TLGQYDtlY,716
3
+ atoti_limits/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ atoti_client_limits-6.2.0.dist-info/WHEEL,sha256=f5fWSvWsg5Knq5GWa6t1nJIug0Tqo69GqAWD_9LbBKw,81
5
+ atoti_client_limits-6.2.0.dist-info/METADATA,sha256=uyhY6vrJwNmZtW9aJDYaqO6tb5BT3oAGf8ZxvqP2nhs,722
6
+ atoti_client_limits-6.2.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: uv 0.11.16
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,136 @@
1
+ """Plugin to connect an Atoti session to a running `Limits <https://docs.activeviam.com/atoti-intelligence/workflows/limits/6.2/introduction-to-atoti-limits>`__ server.
2
+
3
+ .. doctest::
4
+ :hide:
5
+
6
+ >>> from contextlib import ExitStack
7
+ >>> from test_utils import (
8
+ ... generate_key_pair as _generate_key_pair,
9
+ ... limits_server as _start_limits_server,
10
+ ... poll as _poll,
11
+ ... reserve_port,
12
+ ... )
13
+ >>> exit_stack = ExitStack()
14
+ >>> request = getfixture("request")
15
+ >>> request.addfinalizer(exit_stack.close)
16
+
17
+ Atoti server and the Limits server authenticate their requests to each other with JWTs signed by a shared key pair, so both sides must be configured with the same keys:
18
+
19
+ >>> key_pair = _generate_key_pair()
20
+ >>> jwt_config = tt.JwtConfig(key_pair=key_pair)
21
+
22
+ Starting the Limits server:
23
+
24
+ >>> atoti_port = 1337
25
+
26
+ .. doctest::
27
+ :hide:
28
+
29
+ Reserve an actually free port instead of clashing with whatever might already be listening on 1337:
30
+
31
+ >>> atoti_port, release_atoti_port = exit_stack.enter_context(reserve_port())
32
+
33
+ >>> # `_start_limits_server()` is a test helper, not part of the public API.
34
+ >>> # A real project would deploy and run the standalone Limits server itself.
35
+ >>> limits_server = _start_limits_server(
36
+ ... # Set the `activeviam.apps.inter-server-event-service.issuer.target-servers` URL property.
37
+ ... atoti_url=f"http://localhost:{atoti_port}",
38
+ ... # Set the `atoti.jwt.key.public` and `atoti.jwt.key.private` properties.
39
+ ... jwt_config=jwt_config,
40
+ ... )
41
+
42
+ .. doctest::
43
+ :hide:
44
+
45
+ >>> limits_server = exit_stack.enter_context(limits_server)
46
+
47
+ .. doctest::
48
+ :hide:
49
+
50
+ >>> release_atoti_port()
51
+
52
+ >>> from atoti_limits import LimitsConfig
53
+ >>> session_config = tt.SessionConfig(
54
+ ... limits=LimitsConfig(url=limits_server.url),
55
+ ... port=atoti_port,
56
+ ... security=tt.SecurityConfig(jwt=jwt_config),
57
+ ... )
58
+ >>> session = tt.Session.start(session_config)
59
+
60
+ .. doctest::
61
+ :hide:
62
+
63
+ >>> _ = exit_stack.enter_context(session)
64
+
65
+ Configuring the data model, giving the cube a slicing date hierarchy since Atoti Limits evaluates limits at specific points in time:
66
+
67
+ >>> sales_df = pd.DataFrame(
68
+ ... {
69
+ ... "ID": ["S0", "S1"],
70
+ ... "Date": pd.to_datetime(["2026-01-30", "2026-01-31"]),
71
+ ... "Quantity": [1.0, 2.0],
72
+ ... }
73
+ ... )
74
+ >>> table = session.read_pandas(sales_df, keys={"ID"}, table_name="Example")
75
+ >>> cube = session.create_cube(table)
76
+ >>> cube.hierarchies["Date"].slicing = True
77
+
78
+ Configuring the technical user expected by the Limits server:
79
+
80
+ >>> admin_username, admin_password = "admin", "admin"
81
+ >>> session.security.individual_roles[admin_username] = {
82
+ ... "ROLE_ACTIVITI_ADMIN",
83
+ ... "ROLE_ACTIVITI_USER",
84
+ ... "ROLE_ADMIN",
85
+ ... "ROLE_AUTO_APPROVE_LIMIT",
86
+ ... "ROLE_LIMITS",
87
+ ... "ROLE_MANAGERS",
88
+ ... "ROLE_USER",
89
+ ... "ROLE_USERS",
90
+ ... }
91
+ >>> session.security.basic_authentication.credentials[admin_username] = admin_password
92
+
93
+ Initiating the connection:
94
+
95
+ >>> import httpx2
96
+ >>> _ = httpx2.post(
97
+ ... f"{session.url}/limits/autoconfig/connect",
98
+ ... auth=(admin_username, admin_password),
99
+ ... json={
100
+ ... "atotiBaseUrl": session.url,
101
+ ... "limitsBaseUrl": limits_server.url,
102
+ ... # Must match the name the Atoti Limits server knows this session by.
103
+ ... "serverName": "atoti",
104
+ ... },
105
+ ... ).raise_for_status()
106
+
107
+ The Limits server connects back asynchronously.
108
+ Polling until the connection is established:
109
+
110
+ >>> @_poll()
111
+ ... def check_connected(expect_connected: bool, /) -> bool:
112
+ ... response = httpx2.get(
113
+ ... f"{session.url}/limits/autoconfig/connected",
114
+ ... auth=(admin_username, admin_password),
115
+ ... ).raise_for_status()
116
+ ... connected = response.json()
117
+ ... assert isinstance(connected, bool), "Unexpected response body."
118
+ ... assert connected == expect_connected
119
+ ... return connected
120
+ >>> check_connected(True)
121
+ True
122
+
123
+ Once connected, the Limits pages in Atoti UI served from :attr:`atoti.Session.url` can be used.
124
+
125
+ The Atoti session can also be disconnected from the Limits server:
126
+
127
+ >>> _ = httpx2.post(
128
+ ... f"{session.url}/limits/autoconfig/disconnect",
129
+ ... auth=(admin_username, admin_password),
130
+ ... ).raise_for_status()
131
+ >>> check_connected(False)
132
+ False
133
+
134
+ """
135
+
136
+ from .limits_config import LimitsConfig as LimitsConfig
@@ -0,0 +1,21 @@
1
+ from typing import final
2
+
3
+ from atoti._pydantic import PYDANTIC_CONFIG as _PYDANTIC_CONFIG
4
+ from pydantic.dataclasses import dataclass
5
+
6
+
7
+ @final
8
+ @dataclass(config=_PYDANTIC_CONFIG, frozen=True, kw_only=True)
9
+ class LimitsConfig:
10
+ """Configuration for connecting to an Atoti Limits server.
11
+
12
+ When :attr:`atoti.SessionConfig.limits` is not ``None``, Atoti Limits will be auto-configured on the :class:`~atoti.Session` and the Atoti UI Limits extension will be enabled.
13
+
14
+ >>> from atoti_limits import LimitsConfig
15
+ >>> limits_config = LimitsConfig(url="http://localhost:3090")
16
+ >>> session_config = tt.SessionConfig(limits=limits_config)
17
+
18
+ """
19
+
20
+ url: str
21
+ """Base URL of the Atoti Limits server."""
atoti_limits/py.typed ADDED
File without changes