plansom-sdk 0.0.1__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.
Files changed (36) hide show
  1. plansom_sdk-0.0.1/LICENSE +177 -0
  2. plansom_sdk-0.0.1/PKG-INFO +173 -0
  3. plansom_sdk-0.0.1/README.md +152 -0
  4. plansom_sdk-0.0.1/plansom_sdk/__init__.py +21 -0
  5. plansom_sdk-0.0.1/plansom_sdk/_version.py +6 -0
  6. plansom_sdk-0.0.1/plansom_sdk/async_client.py +67 -0
  7. plansom_sdk-0.0.1/plansom_sdk/auth.py +265 -0
  8. plansom_sdk-0.0.1/plansom_sdk/client.py +67 -0
  9. plansom_sdk-0.0.1/plansom_sdk/exceptions.py +72 -0
  10. plansom_sdk-0.0.1/plansom_sdk/models.py +382 -0
  11. plansom_sdk-0.0.1/plansom_sdk/pagination.py +99 -0
  12. plansom_sdk-0.0.1/plansom_sdk/py.typed +0 -0
  13. plansom_sdk-0.0.1/plansom_sdk/resources/__init__.py +2 -0
  14. plansom_sdk-0.0.1/plansom_sdk/resources/goals.py +152 -0
  15. plansom_sdk-0.0.1/plansom_sdk/resources/organizations.py +84 -0
  16. plansom_sdk-0.0.1/plansom_sdk/resources/search.py +32 -0
  17. plansom_sdk-0.0.1/plansom_sdk/resources/tasks.py +133 -0
  18. plansom_sdk-0.0.1/plansom_sdk/resources/teams.py +62 -0
  19. plansom_sdk-0.0.1/plansom_sdk/resources/users.py +38 -0
  20. plansom_sdk-0.0.1/plansom_sdk/transport/__init__.py +3 -0
  21. plansom_sdk-0.0.1/plansom_sdk/transport/http.py +170 -0
  22. plansom_sdk-0.0.1/plansom_sdk/transport/retry.py +29 -0
  23. plansom_sdk-0.0.1/plansom_sdk.egg-info/PKG-INFO +173 -0
  24. plansom_sdk-0.0.1/plansom_sdk.egg-info/SOURCES.txt +34 -0
  25. plansom_sdk-0.0.1/plansom_sdk.egg-info/dependency_links.txt +1 -0
  26. plansom_sdk-0.0.1/plansom_sdk.egg-info/requires.txt +9 -0
  27. plansom_sdk-0.0.1/plansom_sdk.egg-info/top_level.txt +1 -0
  28. plansom_sdk-0.0.1/pyproject.toml +47 -0
  29. plansom_sdk-0.0.1/setup.cfg +4 -0
  30. plansom_sdk-0.0.1/tests/test_async_client.py +41 -0
  31. plansom_sdk-0.0.1/tests/test_auth.py +172 -0
  32. plansom_sdk-0.0.1/tests/test_client.py +46 -0
  33. plansom_sdk-0.0.1/tests/test_models.py +148 -0
  34. plansom_sdk-0.0.1/tests/test_pagination.py +43 -0
  35. plansom_sdk-0.0.1/tests/test_schema_conformance.py +148 -0
  36. plansom_sdk-0.0.1/tests/test_transport.py +213 -0
@@ -0,0 +1,177 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
@@ -0,0 +1,173 @@
1
+ Metadata-Version: 2.4
2
+ Name: plansom-sdk
3
+ Version: 0.0.1
4
+ Summary: Python client SDK for Plansom's be3 v3 API.
5
+ License-Expression: Apache-2.0
6
+ Project-URL: Homepage, https://github.com/Plansom/plansom-sdk/tree/main/python
7
+ Project-URL: Repository, https://github.com/Plansom/plansom-sdk
8
+ Project-URL: Issues, https://github.com/Plansom/plansom-sdk/issues
9
+ Requires-Python: >=3.10
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: httpx>=0.28.1
13
+ Requires-Dist: pydantic>=2.11.2
14
+ Provides-Extra: dev
15
+ Requires-Dist: mypy>=1.15.0; extra == "dev"
16
+ Requires-Dist: pytest>=8.0.0; extra == "dev"
17
+ Requires-Dist: pytest-asyncio>=0.24.0; extra == "dev"
18
+ Requires-Dist: respx>=0.21.0; extra == "dev"
19
+ Requires-Dist: PyYAML>=6.0.1; extra == "dev"
20
+ Dynamic: license-file
21
+
22
+ # Plansom SDK — Python
23
+
24
+ Python client for Plansom's `be3` v3 API. Ships both a sync and an async client from one package.
25
+ Every request-building, response-parsing, and transport function is written directly against
26
+ [`openapi/v3.yaml`](https://github.com/Plansom/plansom-sdk/blob/main/openapi/v3.yaml).
27
+
28
+ > **Status: OAuth is live, API Key is still pending.** `OAuthTokenAuth` does the authorization-code
29
+ > exchange and transparent refresh for real. API Key issuance hasn't shipped on be3 yet, so
30
+ > `APIKeyAuth` still raises `NotImplementedError`. See
31
+ > [`plansom_sdk/auth.py`](https://github.com/Plansom/plansom-sdk/blob/main/python/plansom_sdk/auth.py).
32
+
33
+ ## Layout
34
+
35
+ ```
36
+ plansom_sdk/
37
+ client.py, async_client.py the public Plansom / PlansomAsync classes
38
+ auth.py API Key (PENDING) / OAuth (live) strategies, see file docstring
39
+ exceptions.py typed exception hierarchy
40
+ models.py pydantic response models
41
+ pagination.py page-iteration helper for list endpoints (sync + async)
42
+ _version.py single source of truth for __version__ (also used for the User-Agent header)
43
+ py.typed PEP 561 marker — this package's type hints are checked, not decorative
44
+ transport/
45
+ http.py SyncTransport / AsyncTransport — request building, retry, error translation
46
+ retry.py retry configuration
47
+ resources/
48
+ goals.py, tasks.py, users.py, teams.py, organizations.py, search.py
49
+ one resource class (+ async twin) per file, 34 operations
50
+ tests/
51
+ ```
52
+
53
+ `transport/` groups the two files responsible for actually talking HTTP; `resources/` groups the
54
+ six per-resource method sets. Everything else (`client.py`, `auth.py`, `exceptions.py`,
55
+ `models.py`, `pagination.py`) is a single cross-cutting concern used by both the sync and async
56
+ client, so it stays at the package root rather than nested.
57
+
58
+ ## Resource scope (v1)
59
+
60
+ Read-only: `goals`, `tasks`, `users`, `teams`, `organizations`, `search` — list / retrieve / search only.
61
+ Write operations and AI Plan integration are deferred to a later phase. 34 operations are implemented
62
+ as SDK methods, each with its response model fields and path/query parameters read directly from
63
+ [`openapi/v3.yaml`](https://github.com/Plansom/plansom-sdk/blob/main/openapi/v3.yaml).
64
+
65
+ ## Usage
66
+
67
+ OAuth (live today — third-party app acting on behalf of its own end-user):
68
+
69
+ ```python
70
+ from plansom_sdk import Plansom
71
+ from plansom_sdk.auth import OAuthTokenAuth
72
+
73
+ # Right after your redirect handler receives `?code=...`:
74
+ auth = OAuthTokenAuth.from_authorization_code(
75
+ code=request.GET["code"],
76
+ client_id="...",
77
+ client_secret="...",
78
+ redirect_uri="https://myapp.example/oauth/callback",
79
+ )
80
+ client = Plansom(auth=auth)
81
+ page = client.goals.list(organization=org_id) # refreshes transparently once the token nears expiry
82
+
83
+ # async
84
+ from plansom_sdk import PlansomAsync
85
+ client = PlansomAsync(auth=auth)
86
+ page = await client.goals.list(organization=org_id)
87
+ ```
88
+
89
+ `OAuthTokenAuth` only reaches the `read:goals_tasks`-scoped `goals`/`tasks` endpoints — be3 doesn't
90
+ authenticate OAuth tokens anywhere else (see "OAuth" below). Restoring a token you already have and
91
+ holding a refresh token without going through the exchange are both supported too — see
92
+ [`plansom_sdk/auth.py`](https://github.com/Plansom/plansom-sdk/blob/main/python/plansom_sdk/auth.py)'s docstring for both shapes.
93
+
94
+ API Key (once be3 ships issuance):
95
+
96
+ ```python
97
+ from plansom_sdk.auth import APIKeyAuth
98
+
99
+ client = Plansom(auth=APIKeyAuth(api_key="pk_live_..."))
100
+ page = client.goals.list()
101
+ ```
102
+
103
+ ## Design notes worth knowing before extending this
104
+
105
+ - **List-endpoint filters**: be3's list endpoints each expose ~15-18 near-identical DRF filter
106
+ query params. Rather than naming all of them on every method, the common ones (`page`,
107
+ `page_size`, `search`, `ordering`) are explicit and typed; the rest pass through a loose
108
+ `**filters` kwarg straight into the query string. See `resources/goals.py`'s module docstring for
109
+ the tradeoff (no autocomplete/typo-catching on the long tail of filter names).
110
+ - **String IDs and timestamps**: UUID and datetime fields stay as `str` rather than being parsed
111
+ into `uuid.UUID`/`datetime` objects, to keep every model a flat, direct field list. See
112
+ `models.py`'s module docstring.
113
+ - **One generic `Paginated[T]`**: instead of a distinct wrapper class per list response, `models.Paginated`
114
+ is one pydantic generic model parameterized by item type — `Paginated[Goal].model_validate(data)`.
115
+ Some sub-list endpoints (shared-members, shared-teams, attachments, acceptance-tests) don't
116
+ paginate at all and return plain `List[Model]` instead — see the relevant resource file.
117
+ - **Every model field is `Optional` except `id`**: regardless of what the schema marks "required."
118
+ A DRF read serializer's "required" is a weaker guarantee than it looks — see `goal_type`'s write-
119
+ side validation gap below — so parsing must not hard-fail on a missing key. `id` is the one
120
+ exception, since it's about as close to guaranteed-present as any field gets. Stated once in
121
+ `models.py`'s module docstring rather than justified per field.
122
+ - **`goal_type`/`task_type` are plain `str`, not `Literal`** — verified directly against be3 source:
123
+ `task_type`'s write-side serializer uses a bare `CharField`, not a `ChoiceField`, so arbitrary
124
+ strings can be written today with zero validation. A strict `Literal` would make a real, reachable
125
+ API response fail to parse. The right fix is on the backend, not papered over here — but the SDK
126
+ stays lenient regardless, since even a backend fix wouldn't retroactively clean up existing data.
127
+ - **OAuth**: OAuth-authenticated requests are served by the same `/api/v3/goals/` and
128
+ `/api/v3/tasks/` endpoints as any other authenticated caller, gated by a `read:goals_tasks` scope
129
+ check — there's no OAuth-only endpoint surface. That's why `Goals`/`Tasks` need no OAuth-specific
130
+ routing: an `OAuthTokenAuth`-authenticated client calls the same resource methods as an
131
+ `APIKeyAuth`-authenticated one. `client.users`/`teams`/`organizations`/`search` aren't reachable
132
+ under OAuth auth (be3 doesn't authenticate OAuth tokens on those endpoints) — not guarded against
133
+ client-side, since letting be3's own error surface is simpler than duplicating that policy here
134
+ and risking drift; the resulting `401` surfaces as `PlansomAuthError`, same as any other auth
135
+ failure.
136
+
137
+ `AuthStrategy` exposes both `get_token()` (sync) and `async_get_token()` (defaults to the sync
138
+ path — correct for anything with no I/O). `OAuthTokenAuth` overrides both independently (sync
139
+ `httpx.Client` / async `httpx.AsyncClient`) so the async client's refresh never blocks the event
140
+ loop with a sync HTTP call — see `transport/http.py`'s `AsyncTransport.get`, which `await`s the
141
+ token callable. Refresh is proactive — checked and done inside `get_token`/`async_get_token`, 60s
142
+ before `expires_at` — rather than reactive-on-401, so `transport/http.py` stays completely
143
+ unaware refresh exists at all.
144
+
145
+ ## Reliability and typing
146
+
147
+ - Every request has a bounded timeout (`DEFAULT_TIMEOUT_SECONDS = 30.0` in `transport/http.py`)
148
+ unless a caller passes `timeout_ms` explicitly.
149
+ - The retry loop (exponential backoff, `transport/retry.py`) covers both retryable HTTP status
150
+ codes and transport-level failures (timeouts, connection resets, DNS) with the same attempt
151
+ budget — the latter surface as `PlansomConnectionError`, never a raw `httpx` exception, so callers
152
+ only ever need to catch this package's own exception hierarchy.
153
+ - PEP 561 typed (`py.typed` ships in the built package) and `mypy`-clean.
154
+ - `pagination.paginate`/`async_paginate` walk every page of a list endpoint for both clients.
155
+ - Every request sends `User-Agent: plansom-sdk-python/<version>` (`_version.py`).
156
+
157
+ ## Tests
158
+
159
+ ```
160
+ pip install -e ".[dev]"
161
+ pytest
162
+ ```
163
+
164
+ Covers client construction and auth behavior (`test_client.py`/`test_async_client.py`), the OAuth
165
+ exchange/refresh flow respx-mocked against `/o/token/` (`test_auth.py`), sync/async pagination
166
+ (`test_pagination.py`), pydantic model parsing (`test_models.py`), the HTTP transport layer —
167
+ successful requests, error-status mapping, retries, connection failures — respx-mocked without a
168
+ real network call (`test_transport.py`), and that every field a resource method's return type
169
+ relies on still exists in `openapi/v3.yaml`'s current schema (`test_schema_conformance.py`).
170
+
171
+ ```
172
+ mypy plansom_sdk/
173
+ ```
@@ -0,0 +1,152 @@
1
+ # Plansom SDK — Python
2
+
3
+ Python client for Plansom's `be3` v3 API. Ships both a sync and an async client from one package.
4
+ Every request-building, response-parsing, and transport function is written directly against
5
+ [`openapi/v3.yaml`](https://github.com/Plansom/plansom-sdk/blob/main/openapi/v3.yaml).
6
+
7
+ > **Status: OAuth is live, API Key is still pending.** `OAuthTokenAuth` does the authorization-code
8
+ > exchange and transparent refresh for real. API Key issuance hasn't shipped on be3 yet, so
9
+ > `APIKeyAuth` still raises `NotImplementedError`. See
10
+ > [`plansom_sdk/auth.py`](https://github.com/Plansom/plansom-sdk/blob/main/python/plansom_sdk/auth.py).
11
+
12
+ ## Layout
13
+
14
+ ```
15
+ plansom_sdk/
16
+ client.py, async_client.py the public Plansom / PlansomAsync classes
17
+ auth.py API Key (PENDING) / OAuth (live) strategies, see file docstring
18
+ exceptions.py typed exception hierarchy
19
+ models.py pydantic response models
20
+ pagination.py page-iteration helper for list endpoints (sync + async)
21
+ _version.py single source of truth for __version__ (also used for the User-Agent header)
22
+ py.typed PEP 561 marker — this package's type hints are checked, not decorative
23
+ transport/
24
+ http.py SyncTransport / AsyncTransport — request building, retry, error translation
25
+ retry.py retry configuration
26
+ resources/
27
+ goals.py, tasks.py, users.py, teams.py, organizations.py, search.py
28
+ one resource class (+ async twin) per file, 34 operations
29
+ tests/
30
+ ```
31
+
32
+ `transport/` groups the two files responsible for actually talking HTTP; `resources/` groups the
33
+ six per-resource method sets. Everything else (`client.py`, `auth.py`, `exceptions.py`,
34
+ `models.py`, `pagination.py`) is a single cross-cutting concern used by both the sync and async
35
+ client, so it stays at the package root rather than nested.
36
+
37
+ ## Resource scope (v1)
38
+
39
+ Read-only: `goals`, `tasks`, `users`, `teams`, `organizations`, `search` — list / retrieve / search only.
40
+ Write operations and AI Plan integration are deferred to a later phase. 34 operations are implemented
41
+ as SDK methods, each with its response model fields and path/query parameters read directly from
42
+ [`openapi/v3.yaml`](https://github.com/Plansom/plansom-sdk/blob/main/openapi/v3.yaml).
43
+
44
+ ## Usage
45
+
46
+ OAuth (live today — third-party app acting on behalf of its own end-user):
47
+
48
+ ```python
49
+ from plansom_sdk import Plansom
50
+ from plansom_sdk.auth import OAuthTokenAuth
51
+
52
+ # Right after your redirect handler receives `?code=...`:
53
+ auth = OAuthTokenAuth.from_authorization_code(
54
+ code=request.GET["code"],
55
+ client_id="...",
56
+ client_secret="...",
57
+ redirect_uri="https://myapp.example/oauth/callback",
58
+ )
59
+ client = Plansom(auth=auth)
60
+ page = client.goals.list(organization=org_id) # refreshes transparently once the token nears expiry
61
+
62
+ # async
63
+ from plansom_sdk import PlansomAsync
64
+ client = PlansomAsync(auth=auth)
65
+ page = await client.goals.list(organization=org_id)
66
+ ```
67
+
68
+ `OAuthTokenAuth` only reaches the `read:goals_tasks`-scoped `goals`/`tasks` endpoints — be3 doesn't
69
+ authenticate OAuth tokens anywhere else (see "OAuth" below). Restoring a token you already have and
70
+ holding a refresh token without going through the exchange are both supported too — see
71
+ [`plansom_sdk/auth.py`](https://github.com/Plansom/plansom-sdk/blob/main/python/plansom_sdk/auth.py)'s docstring for both shapes.
72
+
73
+ API Key (once be3 ships issuance):
74
+
75
+ ```python
76
+ from plansom_sdk.auth import APIKeyAuth
77
+
78
+ client = Plansom(auth=APIKeyAuth(api_key="pk_live_..."))
79
+ page = client.goals.list()
80
+ ```
81
+
82
+ ## Design notes worth knowing before extending this
83
+
84
+ - **List-endpoint filters**: be3's list endpoints each expose ~15-18 near-identical DRF filter
85
+ query params. Rather than naming all of them on every method, the common ones (`page`,
86
+ `page_size`, `search`, `ordering`) are explicit and typed; the rest pass through a loose
87
+ `**filters` kwarg straight into the query string. See `resources/goals.py`'s module docstring for
88
+ the tradeoff (no autocomplete/typo-catching on the long tail of filter names).
89
+ - **String IDs and timestamps**: UUID and datetime fields stay as `str` rather than being parsed
90
+ into `uuid.UUID`/`datetime` objects, to keep every model a flat, direct field list. See
91
+ `models.py`'s module docstring.
92
+ - **One generic `Paginated[T]`**: instead of a distinct wrapper class per list response, `models.Paginated`
93
+ is one pydantic generic model parameterized by item type — `Paginated[Goal].model_validate(data)`.
94
+ Some sub-list endpoints (shared-members, shared-teams, attachments, acceptance-tests) don't
95
+ paginate at all and return plain `List[Model]` instead — see the relevant resource file.
96
+ - **Every model field is `Optional` except `id`**: regardless of what the schema marks "required."
97
+ A DRF read serializer's "required" is a weaker guarantee than it looks — see `goal_type`'s write-
98
+ side validation gap below — so parsing must not hard-fail on a missing key. `id` is the one
99
+ exception, since it's about as close to guaranteed-present as any field gets. Stated once in
100
+ `models.py`'s module docstring rather than justified per field.
101
+ - **`goal_type`/`task_type` are plain `str`, not `Literal`** — verified directly against be3 source:
102
+ `task_type`'s write-side serializer uses a bare `CharField`, not a `ChoiceField`, so arbitrary
103
+ strings can be written today with zero validation. A strict `Literal` would make a real, reachable
104
+ API response fail to parse. The right fix is on the backend, not papered over here — but the SDK
105
+ stays lenient regardless, since even a backend fix wouldn't retroactively clean up existing data.
106
+ - **OAuth**: OAuth-authenticated requests are served by the same `/api/v3/goals/` and
107
+ `/api/v3/tasks/` endpoints as any other authenticated caller, gated by a `read:goals_tasks` scope
108
+ check — there's no OAuth-only endpoint surface. That's why `Goals`/`Tasks` need no OAuth-specific
109
+ routing: an `OAuthTokenAuth`-authenticated client calls the same resource methods as an
110
+ `APIKeyAuth`-authenticated one. `client.users`/`teams`/`organizations`/`search` aren't reachable
111
+ under OAuth auth (be3 doesn't authenticate OAuth tokens on those endpoints) — not guarded against
112
+ client-side, since letting be3's own error surface is simpler than duplicating that policy here
113
+ and risking drift; the resulting `401` surfaces as `PlansomAuthError`, same as any other auth
114
+ failure.
115
+
116
+ `AuthStrategy` exposes both `get_token()` (sync) and `async_get_token()` (defaults to the sync
117
+ path — correct for anything with no I/O). `OAuthTokenAuth` overrides both independently (sync
118
+ `httpx.Client` / async `httpx.AsyncClient`) so the async client's refresh never blocks the event
119
+ loop with a sync HTTP call — see `transport/http.py`'s `AsyncTransport.get`, which `await`s the
120
+ token callable. Refresh is proactive — checked and done inside `get_token`/`async_get_token`, 60s
121
+ before `expires_at` — rather than reactive-on-401, so `transport/http.py` stays completely
122
+ unaware refresh exists at all.
123
+
124
+ ## Reliability and typing
125
+
126
+ - Every request has a bounded timeout (`DEFAULT_TIMEOUT_SECONDS = 30.0` in `transport/http.py`)
127
+ unless a caller passes `timeout_ms` explicitly.
128
+ - The retry loop (exponential backoff, `transport/retry.py`) covers both retryable HTTP status
129
+ codes and transport-level failures (timeouts, connection resets, DNS) with the same attempt
130
+ budget — the latter surface as `PlansomConnectionError`, never a raw `httpx` exception, so callers
131
+ only ever need to catch this package's own exception hierarchy.
132
+ - PEP 561 typed (`py.typed` ships in the built package) and `mypy`-clean.
133
+ - `pagination.paginate`/`async_paginate` walk every page of a list endpoint for both clients.
134
+ - Every request sends `User-Agent: plansom-sdk-python/<version>` (`_version.py`).
135
+
136
+ ## Tests
137
+
138
+ ```
139
+ pip install -e ".[dev]"
140
+ pytest
141
+ ```
142
+
143
+ Covers client construction and auth behavior (`test_client.py`/`test_async_client.py`), the OAuth
144
+ exchange/refresh flow respx-mocked against `/o/token/` (`test_auth.py`), sync/async pagination
145
+ (`test_pagination.py`), pydantic model parsing (`test_models.py`), the HTTP transport layer —
146
+ successful requests, error-status mapping, retries, connection failures — respx-mocked without a
147
+ real network call (`test_transport.py`), and that every field a resource method's return type
148
+ relies on still exists in `openapi/v3.yaml`'s current schema (`test_schema_conformance.py`).
149
+
150
+ ```
151
+ mypy plansom_sdk/
152
+ ```
@@ -0,0 +1,21 @@
1
+ """Plansom SDK — Python client for be3's v3 API."""
2
+
3
+ from ._version import __version__
4
+ from .client import Plansom
5
+ from .async_client import PlansomAsync
6
+ from .exceptions import (
7
+ PlansomError,
8
+ PlansomAPIError,
9
+ PlansomAuthError,
10
+ PlansomConnectionError,
11
+ )
12
+
13
+ __all__ = [
14
+ "Plansom",
15
+ "PlansomAsync",
16
+ "PlansomError",
17
+ "PlansomAPIError",
18
+ "PlansomAuthError",
19
+ "PlansomConnectionError",
20
+ "__version__",
21
+ ]
@@ -0,0 +1,6 @@
1
+ """Single source of truth for the package version, kept separate from
2
+ __init__.py so leaf modules (e.g. transport/http.py, for the User-Agent
3
+ header) can import it without risking a circular import through the
4
+ package's own __init__.py."""
5
+
6
+ __version__ = "0.0.1"
@@ -0,0 +1,67 @@
1
+ """Plansom SDK — asynchronous client. Mirrors client.py."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Optional
6
+
7
+ from .auth import AuthStrategy, OAuthTokenAuth
8
+ from .resources.goals import AsyncGoals
9
+ from .resources.organizations import AsyncOrganizations
10
+ from .resources.search import AsyncSearch
11
+ from .resources.tasks import AsyncTasks
12
+ from .resources.teams import AsyncTeams
13
+ from .resources.users import AsyncUsers
14
+ from .transport.http import DEFAULT_BASE_URL, AsyncTransport
15
+ from .transport.retry import RetryConfig
16
+
17
+
18
+ def _require_auth(auth: Optional[AuthStrategy]):
19
+ async def get_token() -> str:
20
+ if auth is None:
21
+ raise RuntimeError("PlansomAsync(auth=...) is required to make API calls.")
22
+ return await auth.async_get_token()
23
+
24
+ return get_token
25
+
26
+
27
+ class PlansomAsync:
28
+ """Asynchronous Plansom API client.
29
+
30
+ Usage:
31
+ from plansom_sdk import PlansomAsync
32
+ from plansom_sdk.auth import OAuthTokenAuth
33
+
34
+ client = PlansomAsync(auth=await OAuthTokenAuth.from_authorization_code_async(...))
35
+ page = await client.goals.list(organization=org_id)
36
+ """
37
+
38
+ def __init__(
39
+ self,
40
+ auth: Optional[AuthStrategy] = None,
41
+ *,
42
+ base_url: Optional[str] = None,
43
+ timeout_ms: Optional[int] = None,
44
+ retry_config: Optional[RetryConfig] = None,
45
+ ) -> None:
46
+ resolved_base_url = (base_url or DEFAULT_BASE_URL).rstrip("/")
47
+ if isinstance(auth, OAuthTokenAuth) and auth.base_url != resolved_base_url:
48
+ raise ValueError(
49
+ f"PlansomAsync is configured for {resolved_base_url!r} but its OAuthTokenAuth is "
50
+ f"configured for {auth.base_url!r} — resource calls and token refresh would "
51
+ f"silently hit different environments."
52
+ )
53
+ self._transport = AsyncTransport(
54
+ _require_auth(auth), base_url=base_url, timeout_ms=timeout_ms, retry_config=retry_config
55
+ )
56
+ self.goals = AsyncGoals(self._transport)
57
+ self.tasks = AsyncTasks(self._transport)
58
+ self.users = AsyncUsers(self._transport)
59
+ self.teams = AsyncTeams(self._transport)
60
+ self.organizations = AsyncOrganizations(self._transport)
61
+ self.search = AsyncSearch(self._transport)
62
+
63
+ async def __aenter__(self) -> "PlansomAsync":
64
+ return self
65
+
66
+ async def __aexit__(self, *exc_info) -> None:
67
+ await self._transport.aclose()