anaplan-sdk 0.4.4a3__tar.gz → 0.4.5__tar.gz
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.
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/.github/workflows/docs.yml +3 -8
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/.github/workflows/lint.yml +1 -1
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/.github/workflows/tests.yml +1 -1
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/PKG-INFO +5 -2
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/README.md +2 -1
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/anaplan_sdk/__init__.py +2 -2
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/anaplan_sdk/_async_clients/_bulk.py +11 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/anaplan_sdk/_auth.py +79 -14
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/anaplan_sdk/_clients/_bulk.py +11 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/anaplan_sdk/models/_bulk.py +2 -2
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/docs/guides/authentication.md +93 -9
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/docs/guides/bulk.md +18 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/docs/guides/transactional.md +2 -2
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/mkdocs.yml +5 -5
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/pyproject.toml +13 -9
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/uv.lock +1310 -1164
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/.github/dependabot.yml +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/.gitignore +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/.pre-commit-config.yaml +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/LICENSE +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/anaplan_sdk/_async_clients/__init__.py +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/anaplan_sdk/_async_clients/_alm.py +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/anaplan_sdk/_async_clients/_audit.py +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/anaplan_sdk/_async_clients/_cloud_works.py +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/anaplan_sdk/_async_clients/_cw_flow.py +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/anaplan_sdk/_async_clients/_transactional.py +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/anaplan_sdk/_base.py +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/anaplan_sdk/_clients/__init__.py +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/anaplan_sdk/_clients/_alm.py +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/anaplan_sdk/_clients/_audit.py +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/anaplan_sdk/_clients/_cloud_works.py +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/anaplan_sdk/_clients/_cw_flow.py +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/anaplan_sdk/_clients/_transactional.py +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/anaplan_sdk/_oauth.py +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/anaplan_sdk/exceptions.py +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/anaplan_sdk/models/__init__.py +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/anaplan_sdk/models/_alm.py +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/anaplan_sdk/models/_base.py +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/anaplan_sdk/models/_transactional.py +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/anaplan_sdk/models/cloud_works.py +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/anaplan_sdk/models/flows.py +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/docs/anaplan_explained.md +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/docs/api/async/async_alm_client.md +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/docs/api/async/async_audit_client.md +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/docs/api/async/async_client.md +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/docs/api/async/async_cw_client.md +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/docs/api/async/async_flows_client.md +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/docs/api/async/async_oauth_client.md +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/docs/api/async/async_transactional_client.md +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/docs/api/exceptions.md +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/docs/api/models/alm.md +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/docs/api/models/bulk.md +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/docs/api/models/cloud_works.md +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/docs/api/models/flows.md +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/docs/api/models/transactional.md +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/docs/api/sync/sync_alm_client.md +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/docs/api/sync/sync_audit_client.md +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/docs/api/sync/sync_client.md +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/docs/api/sync/sync_cw_client.md +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/docs/api/sync/sync_flows_client.md +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/docs/api/sync/sync_oauth_client.md +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/docs/api/sync/sync_transactional_client.md +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/docs/assets/overview.html +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/docs/css/styles.css +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/docs/guides/alm.md +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/docs/guides/audit.md +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/docs/guides/bulk_vs_transactional.md +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/docs/guides/cloud_works.md +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/docs/guides/index.md +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/docs/guides/logging.md +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/docs/guides/multiple_models.md +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/docs/img/anaplan-sdk.webp +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/docs/index.md +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/docs/installation.md +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/docs/js/assets/hljs.js +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/docs/js/assets/hljs.min.js +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/docs/js/assets/python.js +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/docs/js/assets/python.min.js +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/docs/js/highlight.js +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/docs/js/highlight.min.js +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/docs/quickstart.md +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/tests/async/conftest.py +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/tests/async/test_async_alm_client.py +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/tests/async/test_async_audit_client.py +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/tests/async/test_async_client.py +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/tests/async/test_async_cloud_works_client.py +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/tests/async/test_async_flows_client.py +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/tests/async/test_async_transactional_client.py +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/tests/conftest.py +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/tests/sync/conftest.py +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/tests/sync/test_alm_client.py +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/tests/sync/test_audit_client.py +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/tests/sync/test_client.py +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/tests/sync/test_cloud_works_client.py +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/tests/sync/test_flows_client.py +0 -0
- {anaplan_sdk-0.4.4a3 → anaplan_sdk-0.4.5}/tests/sync/test_transactional_client.py +0 -0
@@ -3,11 +3,13 @@ on:
|
|
3
3
|
push:
|
4
4
|
branches:
|
5
5
|
- master
|
6
|
+
workflow_dispatch:
|
7
|
+
|
6
8
|
permissions:
|
7
9
|
contents: write
|
8
10
|
jobs:
|
9
11
|
deploy:
|
10
|
-
runs-on: ubuntu-
|
12
|
+
runs-on: ubuntu-22.04
|
11
13
|
steps:
|
12
14
|
- uses: actions/checkout@v4
|
13
15
|
- name: Configure Git Credentials
|
@@ -17,13 +19,6 @@ jobs:
|
|
17
19
|
- uses: actions/setup-python@v5
|
18
20
|
with:
|
19
21
|
python-version: 3.13
|
20
|
-
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
|
21
|
-
- uses: actions/cache@v4
|
22
|
-
with:
|
23
|
-
key: mkdocs-material-${{ env.cache_id }}
|
24
|
-
path: .cache
|
25
|
-
restore-keys: |
|
26
|
-
mkdocs-material-
|
27
22
|
- name: "Setup"
|
28
23
|
run: |
|
29
24
|
pip install uv
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: anaplan-sdk
|
3
|
-
Version: 0.4.
|
3
|
+
Version: 0.4.5
|
4
4
|
Summary: Streamlined Python Interface for Anaplan
|
5
5
|
Project-URL: Homepage, https://vinzenzklass.github.io/anaplan-sdk/
|
6
6
|
Project-URL: Repository, https://github.com/VinzenzKlass/anaplan-sdk
|
@@ -14,6 +14,8 @@ Requires-Dist: httpx<1.0.0,>=0.27.0
|
|
14
14
|
Requires-Dist: pydantic<3.0.0,>=2.7.2
|
15
15
|
Provides-Extra: cert
|
16
16
|
Requires-Dist: cryptography<46.0.0,>=42.0.7; extra == 'cert'
|
17
|
+
Provides-Extra: keyring
|
18
|
+
Requires-Dist: keyring<26.0.0,>=25.6.0; extra == 'keyring'
|
17
19
|
Provides-Extra: oauth
|
18
20
|
Requires-Dist: oauthlib<4.0.0,>=3.0.0; extra == 'oauth'
|
19
21
|
Description-Content-Type: text/markdown
|
@@ -58,7 +60,8 @@ abstractions over all Anaplan APIs, allowing you to focus on business requiremen
|
|
58
60
|
|
59
61
|
## Getting Started
|
60
62
|
|
61
|
-
Head over to the [Quick Start](quickstart
|
63
|
+
Head over to the [Quick Start](https://vinzenzklass.github.io/anaplan-sdk/quickstart/) for basic usage instructions and
|
64
|
+
examples.
|
62
65
|
|
63
66
|
## Contributing
|
64
67
|
|
@@ -38,7 +38,8 @@ abstractions over all Anaplan APIs, allowing you to focus on business requiremen
|
|
38
38
|
|
39
39
|
## Getting Started
|
40
40
|
|
41
|
-
Head over to the [Quick Start](quickstart
|
41
|
+
Head over to the [Quick Start](https://vinzenzklass.github.io/anaplan-sdk/quickstart/) for basic usage instructions and
|
42
|
+
examples.
|
42
43
|
|
43
44
|
## Contributing
|
44
45
|
|
@@ -1,12 +1,12 @@
|
|
1
1
|
from ._async_clients import AsyncClient
|
2
|
-
from ._auth import
|
2
|
+
from ._auth import AnaplanLocalOAuth, AnaplanRefreshTokenAuth
|
3
3
|
from ._clients import Client
|
4
4
|
from ._oauth import AsyncOauth, Oauth
|
5
5
|
|
6
6
|
__all__ = [
|
7
7
|
"AsyncClient",
|
8
8
|
"Client",
|
9
|
-
"
|
9
|
+
"AnaplanLocalOAuth",
|
10
10
|
"AnaplanRefreshTokenAuth",
|
11
11
|
"AsyncOauth",
|
12
12
|
"Oauth",
|
@@ -451,6 +451,17 @@ class AsyncClient(_AsyncBaseClient):
|
|
451
451
|
).get("task")
|
452
452
|
)
|
453
453
|
|
454
|
+
async def get_optimizer_log(self, action_id: int, task_id: str) -> bytes:
|
455
|
+
"""
|
456
|
+
Retrieves the solution logs of the specified optimization action task.
|
457
|
+
:param action_id: The identifier of the optimization action that was invoked.
|
458
|
+
:param task_id: The Task identifier, sometimes also referred to as the Correlation Id.
|
459
|
+
:return: The content of the solution logs.
|
460
|
+
"""
|
461
|
+
return await self._get_binary(
|
462
|
+
f"{self._url}/optimizeActions/{action_id}/tasks/{task_id}/solutionLogs"
|
463
|
+
)
|
464
|
+
|
454
465
|
async def invoke_action(self, action_id: int) -> str:
|
455
466
|
"""
|
456
467
|
You may want to consider using `run_action()` instead.
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import logging
|
2
2
|
import os
|
3
3
|
from base64 import b64encode
|
4
|
-
from typing import
|
4
|
+
from typing import Callable
|
5
5
|
|
6
6
|
import httpx
|
7
7
|
|
@@ -10,11 +10,6 @@ from .exceptions import AnaplanException, InvalidCredentialsException, InvalidPr
|
|
10
10
|
|
11
11
|
logger = logging.getLogger("anaplan_sdk")
|
12
12
|
|
13
|
-
AuthCodeCallback = (Callable[[str], str] | Callable[[str], Awaitable[str]]) | None
|
14
|
-
AuthTokenRefreshCallback = (
|
15
|
-
Callable[[dict[str, str]], None] | Callable[[dict[str, str]], Awaitable[None]]
|
16
|
-
) | None
|
17
|
-
|
18
13
|
|
19
14
|
class _AnaplanAuth(httpx.Auth):
|
20
15
|
requires_response_body = True
|
@@ -154,13 +149,14 @@ class _AnaplanCertAuth(_AnaplanAuth):
|
|
154
149
|
raise InvalidPrivateKeyException from error
|
155
150
|
|
156
151
|
|
157
|
-
class
|
152
|
+
class AnaplanLocalOAuth(_AnaplanAuth):
|
158
153
|
def __init__(
|
159
154
|
self,
|
160
155
|
client_id: str,
|
161
156
|
client_secret: str,
|
162
157
|
redirect_uri: str,
|
163
158
|
token: dict[str, str] | None = None,
|
159
|
+
persist_token: bool = False,
|
164
160
|
authorization_url: str = "https://us1a.app.anaplan.com/auth/prelogin",
|
165
161
|
token_url: str = "https://us1a.app.anaplan.com/oauth/token",
|
166
162
|
validation_url: str = "https://auth.anaplan.com/token/validate",
|
@@ -168,7 +164,7 @@ class AnaplanOAuthCodeAuth(_AnaplanAuth):
|
|
168
164
|
state_generator: Callable[[], str] | None = None,
|
169
165
|
):
|
170
166
|
"""
|
171
|
-
Initializes the
|
167
|
+
Initializes the AnaplanLocalOAuth class for OAuth2 authentication using the
|
172
168
|
Authorization Code Flow. This is a utility class for local development and requires user
|
173
169
|
interaction. For Web Applications and other scenarios, refer to `Oauth` or `AsyncOauth`.
|
174
170
|
This class will refresh the access token automatically when it expires.
|
@@ -177,6 +173,15 @@ class AnaplanOAuthCodeAuth(_AnaplanAuth):
|
|
177
173
|
:param client_secret: The client secret of your Anaplan Oauth 2.0 application.
|
178
174
|
:param redirect_uri: The URL to which the user will be redirected after authorizing the
|
179
175
|
application.
|
176
|
+
:param token: The OAuth token dictionary containing at least the `access_token` and
|
177
|
+
`refresh_token`. If not provided, the user will be prompted to interactive
|
178
|
+
authorize the application, if `persist_token` is set to False or no valid refresh
|
179
|
+
token is found in the keyring.
|
180
|
+
:param persist_token: If set to True, the refresh token will be stored in the system's
|
181
|
+
keyring, allowing the application to use the same refresh token across multiple
|
182
|
+
runs. If set to False, the user will be prompted to authorize the application each
|
183
|
+
time. This requires the `keyring` extra to be installed. If a valid refresh token
|
184
|
+
is found in the keyring, it will be used instead of the given `token` parameter.
|
180
185
|
:param authorization_url: The URL to which the user will be redirected to authorize the
|
181
186
|
application. Defaults to the Anaplan Prelogin Page, where the user can select the
|
182
187
|
login method.
|
@@ -185,11 +190,27 @@ class AnaplanOAuthCodeAuth(_AnaplanAuth):
|
|
185
190
|
:param validation_url: The URL to validate the access token.
|
186
191
|
:param scope: The scope of the access request.
|
187
192
|
:param state_generator: A callable that generates a random state string. You can optionally
|
188
|
-
|
189
|
-
|
193
|
+
pass this if you need to customize the state generation logic. If not provided,
|
194
|
+
the state will be generated by `oauthlib`.
|
190
195
|
"""
|
191
|
-
|
192
196
|
self._oauth_token = token or {}
|
197
|
+
self._service_name = "anaplan_sdk"
|
198
|
+
|
199
|
+
if persist_token:
|
200
|
+
try:
|
201
|
+
import keyring
|
202
|
+
|
203
|
+
stored = keyring.get_password(self._service_name, self._service_name)
|
204
|
+
if stored:
|
205
|
+
logger.info("Using persisted OAuth refresh token.")
|
206
|
+
self._oauth_token = {"refresh_token": stored}
|
207
|
+
self._token = "" # Set to blank to trigger the super().__init__ auth request.
|
208
|
+
except ImportError as e:
|
209
|
+
raise AnaplanException(
|
210
|
+
"keyring is not available. Please install anaplan-sdk with the keyring extra "
|
211
|
+
"`pip install anaplan-sdk[keyring]` or install keyring separately."
|
212
|
+
) from e
|
213
|
+
self._persist_token = persist_token
|
193
214
|
self._oauth = _OAuthRequestFactory(
|
194
215
|
client_id=client_id,
|
195
216
|
client_secret=client_secret,
|
@@ -200,10 +221,20 @@ class AnaplanOAuthCodeAuth(_AnaplanAuth):
|
|
200
221
|
validation_url=validation_url,
|
201
222
|
state_generator=state_generator,
|
202
223
|
)
|
203
|
-
if not
|
224
|
+
if not self._oauth_token:
|
204
225
|
self.__auth_code_flow()
|
205
226
|
super().__init__(self._token)
|
206
227
|
|
228
|
+
@property
|
229
|
+
def token(self) -> dict[str, str]:
|
230
|
+
"""
|
231
|
+
Returns the current token dictionary. You can safely use the `access_token`, but if you
|
232
|
+
must not use the `refresh_token` outside of this class, if you expect to use this instance
|
233
|
+
further. If you do use the `refresh_token` outside of this class, this will error on the
|
234
|
+
next attempt to refresh the token, as the `refresh_token` can only be used once.
|
235
|
+
"""
|
236
|
+
return self._oauth_token
|
237
|
+
|
207
238
|
def _build_auth_request(self) -> httpx.Request:
|
208
239
|
return self._oauth.refresh_token_request(self._oauth_token["refresh_token"])
|
209
240
|
|
@@ -213,6 +244,12 @@ class AnaplanOAuthCodeAuth(_AnaplanAuth):
|
|
213
244
|
if not response.is_success:
|
214
245
|
raise AnaplanException(f"Authentication failed: {response.status_code} {response.text}")
|
215
246
|
self._oauth_token = response.json()
|
247
|
+
if self._persist_token:
|
248
|
+
import keyring
|
249
|
+
|
250
|
+
keyring.set_password(
|
251
|
+
self._service_name, self._service_name, self._oauth_token["refresh_token"]
|
252
|
+
)
|
216
253
|
self._token: str = self._oauth_token["access_token"]
|
217
254
|
|
218
255
|
def __auth_code_flow(self):
|
@@ -243,8 +280,20 @@ class AnaplanRefreshTokenAuth(_AnaplanAuth):
|
|
243
280
|
):
|
244
281
|
"""
|
245
282
|
This class is a utility class for long-lived `Client` or `AsyncClient` instances that use
|
246
|
-
OAuth.
|
247
|
-
to refresh the
|
283
|
+
OAuth. This class will use the `access_token` until the first request fails with a 401
|
284
|
+
Unauthorized error, at which point it will attempt to refresh the `access_token` using the
|
285
|
+
`refresh_token`. If the refresh fails, it will raise an `InvalidCredentialsException`. The
|
286
|
+
`expires_in` field in the token dictionary is not considered. Manipulating any of the
|
287
|
+
fields in the token dictionary is not recommended and will likely have no effect.
|
288
|
+
|
289
|
+
**For its entire lifetime, you are ceding control of the token to this class.**
|
290
|
+
You must not use the same token simultaneously in multiple instances of this class or
|
291
|
+
outside of it, as this may lead to unexpected behavior when e.g. the refresh token is
|
292
|
+
used, which can only happen once and will lead to errors when attempting to use the same
|
293
|
+
refresh token again elsewhere.
|
294
|
+
|
295
|
+
If you need the token back before this instance is destroyed, you can use the `token`
|
296
|
+
method.
|
248
297
|
|
249
298
|
:param client_id: The client ID of your Anaplan Oauth 2.0 application. This Application
|
250
299
|
must be an Authorization Code Grant application.
|
@@ -256,6 +305,12 @@ class AnaplanRefreshTokenAuth(_AnaplanAuth):
|
|
256
305
|
:param token_url: The URL to post the refresh token request to in order to fetch the access
|
257
306
|
token.
|
258
307
|
"""
|
308
|
+
if not isinstance(token, dict) or not all(
|
309
|
+
key in token for key in ("access_token", "refresh_token")
|
310
|
+
):
|
311
|
+
raise ValueError(
|
312
|
+
"The token must at least contain 'access_token' and 'refresh_token' keys."
|
313
|
+
)
|
259
314
|
self._oauth_token = token
|
260
315
|
self._oauth = _OAuthRequestFactory(
|
261
316
|
client_id=client_id,
|
@@ -265,6 +320,16 @@ class AnaplanRefreshTokenAuth(_AnaplanAuth):
|
|
265
320
|
)
|
266
321
|
super().__init__(self._oauth_token["access_token"])
|
267
322
|
|
323
|
+
@property
|
324
|
+
def token(self) -> dict[str, str]:
|
325
|
+
"""
|
326
|
+
Returns the current OAuth token. You can safely use the `access_token`, but you
|
327
|
+
must not use the `refresh_token` outside of this class, if you expect to use this instance
|
328
|
+
further. If you do use the `refresh_token` outside of this class, this will error on the
|
329
|
+
next attempt to refresh the token, as the `refresh_token` can only be used once.
|
330
|
+
"""
|
331
|
+
return self._oauth_token
|
332
|
+
|
268
333
|
def _build_auth_request(self) -> httpx.Request:
|
269
334
|
return self._oauth.refresh_token_request(self._oauth_token["refresh_token"])
|
270
335
|
|
@@ -438,6 +438,17 @@ class Client(_BaseClient):
|
|
438
438
|
)
|
439
439
|
)
|
440
440
|
|
441
|
+
def get_optimizer_log(self, action_id: int, task_id: str) -> bytes:
|
442
|
+
"""
|
443
|
+
Retrieves the solution logs of the specified optimization action task.
|
444
|
+
:param action_id: The identifier of the optimization action that was invoked.
|
445
|
+
:param task_id: The Task identifier, sometimes also referred to as the Correlation Id.
|
446
|
+
:return: The content of the solution logs.
|
447
|
+
"""
|
448
|
+
return self._get_binary(
|
449
|
+
f"{self._url}/optimizeActions/{action_id}/tasks/{task_id}/solutionLogs"
|
450
|
+
)
|
451
|
+
|
441
452
|
def invoke_action(self, action_id: int) -> str:
|
442
453
|
"""
|
443
454
|
You may want to consider using `run_action()` instead.
|
@@ -145,10 +145,10 @@ class TaskSummary(AnaplanModel):
|
|
145
145
|
|
146
146
|
|
147
147
|
class TaskResultDetail(AnaplanModel):
|
148
|
-
local_message_text: str = Field(description="Error message text.")
|
148
|
+
local_message_text: str | None = Field(None, description="Error message text.")
|
149
149
|
occurrences: int = Field(0, description="The number of occurrences of this error.")
|
150
150
|
type: str = Field(description="The type of this error.")
|
151
|
-
values: list[str] = Field([], description="Further error information if available.")
|
151
|
+
values: list[str | None] = Field([], description="Further error information if available.")
|
152
152
|
|
153
153
|
|
154
154
|
class TaskResult(AnaplanModel):
|
@@ -7,9 +7,9 @@ There are three main ways to authenticate with Anaplan.
|
|
7
7
|
- OAuth2
|
8
8
|
|
9
9
|
Anaplan SDK supports all of them, though Basic Authentication is strictly not recommended for production use.
|
10
|
-
Certificate
|
11
|
-
|
12
|
-
|
10
|
+
Certificate Authentication is currently the most suitable for production use, since the Anaplan OAuth 2.0
|
11
|
+
implementation does not support the `client_credentials` grant type. This means you will have to manually manage the
|
12
|
+
refresh Token if you choose to use OAuth2.
|
13
13
|
|
14
14
|
## Basic Authentication
|
15
15
|
|
@@ -45,7 +45,7 @@ maintain and error-prone.
|
|
45
45
|
|
46
46
|
Certificate Authentication is the most suitable for production use. It uses an X.509 S/MIME Certificate (aka. Client Certificate or HTTPS-Certificate) and Private Key. The Process of acquiring such a certificate is well [documented](https://help.anaplan.com/procure-ca-certificates-47842267-2cb3-4e38-90bf-13b1632bcd44). Anaplan does not support self-signed certificates, so you will need to procure a certificate from a trusted Certificate Authority (CA).
|
47
47
|
|
48
|
-
|
48
|
+
???+ tip "Requires Extra"
|
49
49
|
If you want to use certificate authentication, you need to install the `cert` extra:
|
50
50
|
=== "pip"
|
51
51
|
```shell
|
@@ -96,7 +96,8 @@ in which the authentication flow must occur outside the SDK for the user to log
|
|
96
96
|
|
97
97
|
These Classes exist for convenience only, and you can use any other Library to handle the Oauth2 flow.
|
98
98
|
|
99
|
-
|
99
|
+
A minimal, illustrative example for FastAPI is shown below, but you can use any other Web Framework. This will not run
|
100
|
+
until you implement the TODOs in a suitable way for your purpose.
|
100
101
|
|
101
102
|
??? tip "Requires Extra"
|
102
103
|
If you want to use OAuth2 authentication, you need to install the `oauth` extra:
|
@@ -200,10 +201,10 @@ when it expires.
|
|
200
201
|
|
201
202
|
## OAuth for Local Applications
|
202
203
|
|
203
|
-
For local applications, you can use `
|
204
|
+
For local applications, you can use `AnaplanLocalOAuth` Class to handle the initial Oauth2 `authorization_code` flow
|
204
205
|
and the subsequent token refreshes.
|
205
206
|
|
206
|
-
|
207
|
+
???+ tip "Requires Extra"
|
207
208
|
If you want to use OAuth2 authentication, you need to install the `oauth` extra:
|
208
209
|
=== "pip"
|
209
210
|
```shell
|
@@ -222,7 +223,7 @@ and the subsequent token refreshes.
|
|
222
223
|
=== "Synchronous"
|
223
224
|
```python
|
224
225
|
anaplan = Client(
|
225
|
-
auth=
|
226
|
+
auth=AnaplanLocalOAuth(
|
226
227
|
client_id=os.environ["OAUTH_CLIENT_ID"],
|
227
228
|
client_secret=os.environ["OAUTH_CLIENT_SECRET"],
|
228
229
|
redirect_uri="https://vinzenzklass.github.io/anaplan-sdk",
|
@@ -232,7 +233,7 @@ and the subsequent token refreshes.
|
|
232
233
|
=== "Asynchronous"
|
233
234
|
```python
|
234
235
|
anaplan = AsyncClient(
|
235
|
-
auth=
|
236
|
+
auth=AnaplanLocalOAuth(
|
236
237
|
client_id=os.environ["OAUTH_CLIENT_ID"],
|
237
238
|
client_secret=os.environ["OAUTH_CLIENT_SECRET"],
|
238
239
|
redirect_uri="https://vinzenzklass.github.io/anaplan-sdk",
|
@@ -247,6 +248,89 @@ will need to copy the entire redirect URI from your browser and paste it into th
|
|
247
248
|
Unfortunately, registering localhost redirect URIs is not supported by Anaplan. This means we cannot intercept the
|
248
249
|
redirect URI and extract the `authorization_code` automatically. This is a limitation of Anaplan's OAuth2 implementation. See [this Community Note](https://community.anaplan.com/discussion/156599/oauth-rediredt-url-port-for-desktop-apps).
|
249
250
|
|
251
|
+
## Persisting OAuth Tokens
|
252
|
+
|
253
|
+
The SDK provides the ability to persist OAuth refresh tokens between sessions using the system's secure keyring for
|
254
|
+
local applications. This allows you to avoid having to re-authenticate every time you run your application while using
|
255
|
+
OAuth2.
|
256
|
+
|
257
|
+
???+ tip "Requires Extras"
|
258
|
+
If you want to use persisting Tokens, you need to additionally install the `keyring` extra:
|
259
|
+
=== "pip"
|
260
|
+
```shell
|
261
|
+
pip install anaplan-sdk[oauth,keyring]
|
262
|
+
```
|
263
|
+
===+ "uv"
|
264
|
+
```shell
|
265
|
+
uv add anaplan-sdk[oauth,keyring]
|
266
|
+
```
|
267
|
+
=== "Poetry"
|
268
|
+
```shell
|
269
|
+
poetry add anaplan-sdk[oauth,keyring]
|
270
|
+
```
|
271
|
+
|
272
|
+
This will install [Keyring](https://github.com/jaraco/keyring) to securely store refresh tokens.
|
273
|
+
|
274
|
+
To enable token persistence, set the `persist_token=True` parameter when creating an `AnaplanLocalOAuth` instance:
|
275
|
+
|
276
|
+
=== "Synchronous"
|
277
|
+
```python
|
278
|
+
anaplan = Client(
|
279
|
+
auth=AnaplanLocalOAuth(
|
280
|
+
client_id=os.environ["OAUTH_CLIENT_ID"],
|
281
|
+
client_secret=os.environ["OAUTH_CLIENT_SECRET"],
|
282
|
+
redirect_uri="https://vinzenzklass.github.io/anaplan-sdk",
|
283
|
+
persist_token=True,
|
284
|
+
)
|
285
|
+
)
|
286
|
+
```
|
287
|
+
=== "Asynchronous"
|
288
|
+
```python
|
289
|
+
anaplan = AsyncClient(
|
290
|
+
auth=AnaplanLocalOAuth(
|
291
|
+
client_id=os.environ["OAUTH_CLIENT_ID"],
|
292
|
+
client_secret=os.environ["OAUTH_CLIENT_SECRET"],
|
293
|
+
redirect_uri="https://vinzenzklass.github.io/anaplan-sdk",
|
294
|
+
persist_token=True,
|
295
|
+
)
|
296
|
+
)
|
297
|
+
```
|
298
|
+
When `persist_token` is set to True, the SDK will:
|
299
|
+
|
300
|
+
- Look for a stored refresh token in the system's keyring
|
301
|
+
- If found, use it to obtain a new access token. If also given, this will overwrite the passed `token` parameter.
|
302
|
+
- If not found or if the token is invalid, prompt the user for authentication
|
303
|
+
- After authentication, store the new refresh token in the keyring
|
304
|
+
|
305
|
+
??? note "Keyring Configuration"
|
306
|
+
The keyring library may require additional configuration depending on your environment:
|
307
|
+
|
308
|
+
- In headless environments, you may need to explicitely configure a different keyring backend
|
309
|
+
- Some Linux distributions may require additional packages or configuration
|
310
|
+
|
311
|
+
Configuring the keyring backend is your responsibility as it depends on your specific environment.
|
312
|
+
|
313
|
+
For example, to use the libsecret file backend:
|
314
|
+
|
315
|
+
```python
|
316
|
+
import keyring
|
317
|
+
from keyring.backends import libsecret
|
318
|
+
|
319
|
+
keyring.set_keyring(libsecret.Keyring())
|
320
|
+
```
|
321
|
+
|
322
|
+
For more information, refer to the [keyring documentation](https://github.com/jaraco/keyring).
|
323
|
+
|
324
|
+
## OAuth Token Ownership
|
325
|
+
|
326
|
+
Instances of both `AnaplanLocalOAuth` and `AnaplanRefreshTokenAuth` assert ownership of the token you pass to them
|
327
|
+
for their entire lifetime. This means that you should not use the token outside of these classes, as it may lead to
|
328
|
+
errors when attempting to use the same refresh token in multiple places. You can access the current token by using the
|
329
|
+
`token` property, but you should not use anything other than the `access_token`. You can use this property to
|
330
|
+
reassert control of the OAuth token when the instance is nor longer needed. If you do need to use the token in several
|
331
|
+
places simultaneously, you should use a [custom scheme](#custom-authentication-schemes) to do so and handle all
|
332
|
+
potential conflicts appropriately.
|
333
|
+
|
250
334
|
|
251
335
|
## Custom Authentication Schemes
|
252
336
|
|
@@ -120,6 +120,24 @@ provide the workspace and model IDs.
|
|
120
120
|
await anaplan.run_action(116000000000)
|
121
121
|
...
|
122
122
|
content = await anaplan.get_file(116000000000)
|
123
|
+
|
124
|
+
|
125
|
+
### Optimizer Logs
|
126
|
+
|
127
|
+
You can download the Optimizer Logs from Anaplan. This will give you the Solution Logs produced by Gurobi, which can be
|
128
|
+
very useful for debugging and understanding the performance of your Optimizer models.
|
129
|
+
|
130
|
+
=== "Synchronous"
|
131
|
+
```python
|
132
|
+
log = anaplan.get_optimizer_log(
|
133
|
+
117000000000, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
|
134
|
+
)
|
135
|
+
```
|
136
|
+
=== "Asynchronous"
|
137
|
+
```python
|
138
|
+
log = await anaplan.get_optimizer_log(
|
139
|
+
117000000000, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
|
140
|
+
)
|
123
141
|
```
|
124
142
|
|
125
143
|
## Applications
|
@@ -175,7 +175,7 @@ Warning. To automate this tedious task without losing any data, we can perform f
|
|
175
175
|
)
|
176
176
|
anaplan.transactional.reset_list_index(101000000000)
|
177
177
|
result = anaplan.transactional.insert_list_items(
|
178
|
-
|
178
|
+
101000000000, [e.model_dump() for e in items] # Reimport all fields.
|
179
179
|
)
|
180
180
|
```
|
181
181
|
=== "Asynchronous"
|
@@ -186,6 +186,6 @@ Warning. To automate this tedious task without losing any data, we can perform f
|
|
186
186
|
)
|
187
187
|
await anaplan.transactional.reset_list_index(101000000000)
|
188
188
|
result = await anaplan.transactional.insert_list_items(
|
189
|
-
|
189
|
+
101000000000, [e.model_dump() for e in items] # Reimport all fields.
|
190
190
|
)
|
191
191
|
```
|
@@ -68,11 +68,11 @@ nav:
|
|
68
68
|
- Flows: 'api/sync/sync_flows_client.md'
|
69
69
|
- OAuth: 'api/sync/sync_oauth_client.md'
|
70
70
|
- Models:
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
71
|
+
- ALM: 'api/models/alm.md'
|
72
|
+
- Bulk: 'api/models/bulk.md'
|
73
|
+
- CloudWorks: 'api/models/cloud_works.md'
|
74
|
+
- Flows: 'api/models/flows.md'
|
75
|
+
- Transactional: 'api/models/transactional.md'
|
76
76
|
- Exceptions: 'api/exceptions.md'
|
77
77
|
- Concepts:
|
78
78
|
- Anaplan Basics: 'anaplan_explained.md'
|
@@ -1,6 +1,6 @@
|
|
1
1
|
[project]
|
2
2
|
name = "anaplan-sdk"
|
3
|
-
version = "0.4.
|
3
|
+
version = "0.4.5"
|
4
4
|
description = "Streamlined Python Interface for Anaplan"
|
5
5
|
license = "Apache-2.0"
|
6
6
|
authors = [{ name = "Vinzenz Klass", email = "vinzenz.klass@valantic.com" }]
|
@@ -26,20 +26,24 @@ dependencies = [
|
|
26
26
|
[project.optional-dependencies]
|
27
27
|
cert = ["cryptography>=42.0.7,<46.0.0"]
|
28
28
|
oauth = ["oauthlib>=3.0.0,<4.0.0"]
|
29
|
+
keyring = ["keyring>=25.6.0,<26.0.0"]
|
29
30
|
|
30
31
|
[dependency-groups]
|
31
32
|
dev = [
|
32
|
-
"ruff>=0.
|
33
|
-
"pre-commit>=4.
|
34
|
-
"pytest>=8.
|
35
|
-
"pytest-asyncio>=
|
36
|
-
"pytest-xdist>=3.
|
33
|
+
"ruff>=0.12.8",
|
34
|
+
"pre-commit>=4.3.0",
|
35
|
+
"pytest>=8.4.1",
|
36
|
+
"pytest-asyncio>=1.1.0",
|
37
|
+
"pytest-xdist>=3.8.0",
|
37
38
|
"mkdocs>=1.6.1",
|
38
|
-
"mkdocs-material>=9.
|
39
|
-
"mkdocstrings[python]>=0.
|
40
|
-
"griffe
|
39
|
+
"mkdocs-material>=9.6.16",
|
40
|
+
"mkdocstrings[python]>=0.30.0",
|
41
|
+
"griffe>=1.7.3",
|
42
|
+
"fieldz>=0.1.2",
|
43
|
+
"griffe-fieldz>=0.3.0",
|
41
44
|
"oauthlib>=3.2.2",
|
42
45
|
"cryptography>=45.0.0",
|
46
|
+
"keyring>=25.6.0",
|
43
47
|
]
|
44
48
|
|
45
49
|
[project.urls]
|