flowabbit 1.0.0__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 (35) hide show
  1. flowabbit-1.0.0/CHANGELOG.md +32 -0
  2. flowabbit-1.0.0/LICENSE +201 -0
  3. flowabbit-1.0.0/MANIFEST.in +3 -0
  4. flowabbit-1.0.0/PKG-INFO +330 -0
  5. flowabbit-1.0.0/README.md +300 -0
  6. flowabbit-1.0.0/pyproject.toml +51 -0
  7. flowabbit-1.0.0/setup.cfg +4 -0
  8. flowabbit-1.0.0/src/flowabbit/__init__.py +51 -0
  9. flowabbit-1.0.0/src/flowabbit/client.py +471 -0
  10. flowabbit-1.0.0/src/flowabbit/http_client.py +87 -0
  11. flowabbit-1.0.0/src/flowabbit/resources/__init__.py +1 -0
  12. flowabbit-1.0.0/src/flowabbit/resources/bms.py +29 -0
  13. flowabbit-1.0.0/src/flowabbit/resources/doc.py +92 -0
  14. flowabbit-1.0.0/src/flowabbit/resources/tms.py +245 -0
  15. flowabbit-1.0.0/src/flowabbit/runtime/__init__.py +66 -0
  16. flowabbit-1.0.0/src/flowabbit/runtime/errors.py +164 -0
  17. flowabbit-1.0.0/src/flowabbit/runtime/rate_limit.py +61 -0
  18. flowabbit-1.0.0/src/flowabbit/runtime/retry.py +173 -0
  19. flowabbit-1.0.0/src/flowabbit/runtime/token_manager.py +102 -0
  20. flowabbit-1.0.0/src/flowabbit/runtime/webhook_verifier.py +141 -0
  21. flowabbit-1.0.0/src/flowabbit.egg-info/PKG-INFO +330 -0
  22. flowabbit-1.0.0/src/flowabbit.egg-info/SOURCES.txt +33 -0
  23. flowabbit-1.0.0/src/flowabbit.egg-info/dependency_links.txt +1 -0
  24. flowabbit-1.0.0/src/flowabbit.egg-info/requires.txt +5 -0
  25. flowabbit-1.0.0/src/flowabbit.egg-info/top_level.txt +1 -0
  26. flowabbit-1.0.0/tests/__init__.py +0 -0
  27. flowabbit-1.0.0/tests/conftest.py +107 -0
  28. flowabbit-1.0.0/tests/fixtures/business_error_wire.json +17 -0
  29. flowabbit-1.0.0/tests/test_errors.py +107 -0
  30. flowabbit-1.0.0/tests/test_rate_limit.py +74 -0
  31. flowabbit-1.0.0/tests/test_retry.py +169 -0
  32. flowabbit-1.0.0/tests/test_smoke_create_shipment.py +290 -0
  33. flowabbit-1.0.0/tests/test_tms_operations.py +343 -0
  34. flowabbit-1.0.0/tests/test_token_manager.py +84 -0
  35. flowabbit-1.0.0/tests/test_webhook_verifier.py +171 -0
@@ -0,0 +1,32 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented in this file. The format
4
+ is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and
5
+ this project follows [Semantic Versioning](https://semver.org/).
6
+
7
+ ## [1.0.0] - 2026-12-05
8
+
9
+ First public release of the Flowabbit Python SDK (`pip install flowabbit`).
10
+
11
+ ### Added
12
+
13
+ - Client with one method per Open API operation: `me`, TMS origins, rates,
14
+ shipments (create, modify, query, get, cancel), trackers, manifests and
15
+ handovers; BMS accounts; document center documents (list, get, download,
16
+ merged PDF, document types).
17
+ - OAuth2 client_credentials token manager: lazy fetch, in-memory cache,
18
+ refresh before expiry and on 401.
19
+ - Retry policy: network errors, 429 and 5xx are retried only for idempotent
20
+ requests and replay-safe POSTs (shipment creation when every entry carries
21
+ a `reference_no`); honours `Retry-After` and `RateLimit-Reset`.
22
+ - Typed errors by HTTP status class, carrying the Problem Details `code`,
23
+ `detail` and `request_id`; batch entry errors returned as values.
24
+ - Rate-limit metadata (RFC 9333 `RateLimit-*`, legacy `X-RateLimit-*`) on
25
+ every response.
26
+ - Webhook verifier for Standard Webhooks signatures (`whsec_` secrets,
27
+ multiple signatures, ±5 minute delivery window, optional dedup hook).
28
+ - Document downloads returned as bytes; signed storage redirects are followed
29
+ without the `Authorization` header.
30
+ - Requires Python 3.11 or later; no runtime dependencies.
31
+
32
+ [1.0.0]: https://github.com/flowabbit/flowabbit-python/releases/tag/v1.0.0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 FLOWABBIT PTE. LTD.
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,3 @@
1
+ include CHANGELOG.md
2
+ graft tests
3
+ global-exclude __pycache__ *.py[cod]
@@ -0,0 +1,330 @@
1
+ Metadata-Version: 2.4
2
+ Name: flowabbit
3
+ Version: 1.0.0
4
+ Summary: Flowabbit logistics open API Python SDK
5
+ Author: FLOWABBIT PTE. LTD.
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://flowabbit.com/
8
+ Project-URL: Documentation, https://flowabbit.com/docs
9
+ Project-URL: Repository, https://github.com/flowabbit/flowabbit-python
10
+ Project-URL: Changelog, https://github.com/flowabbit/flowabbit-python/blob/main/CHANGELOG.md
11
+ Project-URL: Issues, https://github.com/flowabbit/flowabbit-python/issues
12
+ Keywords: flowabbit,logistics,sdk
13
+ Classifier: Development Status :: 5 - Production/Stable
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Classifier: Programming Language :: Python :: 3.15
21
+ Classifier: Topic :: Software Development :: Libraries
22
+ Requires-Python: >=3.11
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Provides-Extra: test
26
+ Requires-Dist: pytest>=7.4; extra == "test"
27
+ Requires-Dist: build>=1.0; extra == "test"
28
+ Requires-Dist: twine>=5.0; extra == "test"
29
+ Dynamic: license-file
30
+
31
+ # Flowabbit Python SDK
32
+
33
+ The official Python SDK for the Flowabbit logistics Open API: OAuth token
34
+ handling, safe automatic retries, typed errors, rate-limit metadata and
35
+ webhook signature verification. No runtime dependencies (standard library
36
+ only).
37
+
38
+ ## Requirements
39
+
40
+ - Python 3.11 or later
41
+
42
+ ## Installation
43
+
44
+ ```bash
45
+ pip install flowabbit
46
+ ```
47
+
48
+ ## Quickstart
49
+
50
+ Create a shipment. Every value that identifies your account comes from the
51
+ environment; never hard-code credentials in source, logs or URLs.
52
+
53
+ | Environment variable | Description |
54
+ | --- | --- |
55
+ | `FLOWABBIT_BASE_URL` | Your API domain only, without a path, e.g. `https://<your-domain>` |
56
+ | `FLOWABBIT_CLIENT_ID` | OAuth client id |
57
+ | `FLOWABBIT_CLIENT_SECRET` | OAuth client secret; keep it on your server only |
58
+ | `FLOWABBIT_RATE_ID` | A `rate_id` returned by the rates operation (quote first, with the same addresses and packages) |
59
+
60
+ ```python
61
+ import os
62
+ import sys
63
+
64
+ from flowabbit import FlowabbitApiError, FlowabbitClient
65
+
66
+
67
+ def main() -> int:
68
+ client = FlowabbitClient(
69
+ client_id=os.environ["FLOWABBIT_CLIENT_ID"],
70
+ client_secret=os.environ["FLOWABBIT_CLIENT_SECRET"],
71
+ # Required, no default: your domain only, e.g. https://<your-domain> (no path; the SDK adds the API path prefix)
72
+ base_url=os.environ["FLOWABBIT_BASE_URL"],
73
+ )
74
+ request = {
75
+ "shipments": [
76
+ {
77
+ # rate id returned by the rates operation
78
+ "selected_rate_id": os.environ["FLOWABBIT_RATE_ID"],
79
+ "reference_no": "ORDER-1001",
80
+ "from_address": {
81
+ "name": "Example Warehouse", "street1": "100 Example Road",
82
+ "city": "Los Angeles", "subdivision": "CA", "postal_code": "90001", "country": "US",
83
+ },
84
+ "to_address": {
85
+ "name": "Example Recipient", "street1": "1 Sample Street",
86
+ "city": "Seattle", "subdivision": "WA", "postal_code": "98101", "country": "US",
87
+ "is_residential": True,
88
+ },
89
+ "packages": [{"weight": "1.2", "weight_unit": "kg"}],
90
+ }
91
+ ],
92
+ }
93
+ try:
94
+ # The SDK obtains and refreshes the access token. Because the entry carries a reference_no,
95
+ # the SDK may retry a network failure: a retry that finds the shipment already created reports
96
+ # SHIPMENT_REFERENCE_EXISTS with the existing shipment_id.
97
+ response = client.tms.shipments.create(request)
98
+ except FlowabbitApiError as err:
99
+ print(f"request failed: {err.error_code}: {err.message} (request id {err.request_id})", file=sys.stderr)
100
+ return 1
101
+ print("request id:", response.request_id)
102
+ print("result:", response.data)
103
+ return 0
104
+
105
+
106
+ if __name__ == "__main__":
107
+ sys.exit(main())
108
+ ```
109
+
110
+ ### Base URL and credentials
111
+
112
+ OAuth credentials (client ID / client secret) are created in the Flowabbit
113
+ customer portal (project settings → OAuth clients). Every call acts as the
114
+ customer the credentials belong to, so requests never carry `customer_id`.
115
+
116
+ `base_url` is required and has **no default**: it is the domain you call the
117
+ API on (the domain you read the API documentation from), scheme and host
118
+ only, such as `https://<your-domain>`. The SDK sends the token request to
119
+ `<base_url>/api/v1/oauth/token` and every operation to `<base_url>/api/v1/...`.
120
+ A value with a path (for example `https://<your-domain>/api/v1`) is
121
+ rejected when the client is built.
122
+
123
+ ## Verifying webhooks
124
+
125
+ Deliveries follow the [Standard Webhooks](https://www.standardwebhooks.com)
126
+ specification. `WebhookVerifier` checks the signature headers, the signature
127
+ (constant-time, multiple signatures for secret rotation) and the delivery
128
+ time (±5 minutes), and returns the event.
129
+
130
+ ```python
131
+ from flowabbit import (
132
+ FlowabbitWebhookDuplicateEventError,
133
+ FlowabbitWebhookSignatureError,
134
+ WebhookEvent,
135
+ WebhookVerifier,
136
+ )
137
+
138
+
139
+ def verify_webhook(secret: str, raw_body: bytes, headers: dict[str, str]) -> WebhookEvent:
140
+ """Return the verified event, or raise FlowabbitWebhookSignatureError.
141
+
142
+ `raw_body` must be the exact bytes received, before any JSON parsing.
143
+ Deduplicate on `event.event_id` before processing (it is stable across retries).
144
+ """
145
+ return WebhookVerifier(secret=secret).verify(headers=headers, raw_body=raw_body)
146
+
147
+
148
+ try:
149
+ event = verify_webhook(secret, raw_body, headers)
150
+ # ... process event.event_type / event.payload
151
+ except FlowabbitWebhookDuplicateEventError:
152
+ pass # only raised when you pass dedup_hook: already processed — respond 2xx
153
+ except FlowabbitWebhookSignatureError:
154
+ ... # not authentic — respond 4xx and do not process
155
+ ```
156
+
157
+ Handling a delivery:
158
+
159
+ 1. Keep the endpoint's signing secret (`whsec_...`) on your server only.
160
+ 2. Verify the **raw request body bytes**, before any JSON parsing.
161
+ 3. If verification fails, respond with a 4xx and do not process the event.
162
+ 4. Deduplicate on the event id (`webhook-id`): it is the same for every retry
163
+ of an event, so respond 2xx to events you have already processed.
164
+ 5. Respond 2xx quickly and move slow work to a background job.
165
+
166
+ ## Reference
167
+
168
+ ### Operations
169
+
170
+ Request bodies are plain `dict`s, list filters a `dict` of query parameters
171
+ (`status`, `manifest_no` / `handover_no`, `page`, `page_size`; `None` values
172
+ are left out). Downloads return a `BinaryResponse`: `content` (bytes, never
173
+ parsed as JSON), `content_type`, `filename` (from `Content-Disposition`,
174
+ `None` when the server sends none), `rate_limit`, `request_id`. Every other
175
+ method returns an `ApiResponse`. Path parameters are percent-encoded; an
176
+ empty value, `.` or `..` raises `ValueError` before any request.
177
+
178
+ Automatic retries (network error, 429, 5xx) follow the last column; the OAuth token operation is handled by `TokenManager`.
179
+
180
+ | Operation | HTTP | Method | Retried |
181
+ | --- | --- | --- | --- |
182
+ | `get_me` | `GET /me` | `client.me()` | yes |
183
+ | `list_origins` | `GET /tms/origins` | `client.tms.origins.list()` | yes |
184
+ | `list_rates` | `POST /tms/rates` | `client.tms.rates.list(body)` | yes (a quote charges nothing) |
185
+ | `create_shipments` | `POST /tms/shipments` | `client.tms.shipments.create(body)` | only when every entry has a `reference_no` |
186
+ | `modify_shipment` | `POST /tms/shipments/modify` | `client.tms.shipments.modify(body)` | never |
187
+ | `query_shipments` | `POST /tms/shipments/query` | `client.tms.shipments.query(body)` | yes (read-only) |
188
+ | `get_shipment` | `GET /tms/shipments/{id}` | `client.tms.shipments.get(shipment_id)` | yes |
189
+ | `cancel_shipment` | `POST /tms/shipments/{id}/cancel` | `client.tms.shipments.cancel(shipment_id)` | yes (a repeated cancel returns the current status) |
190
+ | `query_trackers` | `POST /tms/trackers/query` | `client.tms.trackers.query(body)` | yes (read-only) |
191
+ | `request_manifest` | `POST /tms/shipments/manifest` | `client.tms.manifests.request(body)` | yes (a manifested or scheduled shipment returns its `manifest_no` again) |
192
+ | `list_manifests` | `GET /tms/manifests` | `client.tms.manifests.list(query)` | yes |
193
+ | `get_manifest` | `GET /tms/manifests/{manifest_no}` | `client.tms.manifests.get(manifest_no)` | yes |
194
+ | `create_handovers` | `POST /tms/handovers` | `client.tms.handovers.create(body)` | yes (a handed-over shipment returns `already_handed_over` with its `handover_no`) |
195
+ | `list_handovers` | `GET /tms/handovers` | `client.tms.handovers.list(query)` | yes |
196
+ | `get_handover` | `GET /tms/handovers/{handover_no}` | `client.tms.handovers.get(handover_no)` | yes |
197
+ | `find_handovers_by_document` | `GET /tms/handovers/by-document/{document_no}` | `client.tms.handovers.find_by_document(document_no)` | yes |
198
+ | `remove_handover_items` | `POST /tms/handovers/{handover_no}/items/remove` | `client.tms.handovers.remove_items(handover_no, body)` | never |
199
+ | `list_documents` | `GET /doc/documents` | `client.doc.documents.list(ref_type, ref)` | yes |
200
+ | `get_document` | `GET /doc/documents/{id}` | `client.doc.documents.get(document_id)` | yes |
201
+ | `download_document` | `GET /doc/documents/{id}/file` | `client.doc.documents.download(document_id)` | yes |
202
+ | `merge_documents` | `GET /doc/documents/merged` | `client.doc.documents.merged(ref_type, ref, *, types=None, sources=None, print_media=None, document_ids=None)` | yes |
203
+ | `list_document_types` | `GET /doc/document-types` | `client.doc.documents.types()` | yes |
204
+
205
+ ### Documents
206
+
207
+ Labels, customs documents, proof of delivery, carrier manifest forms and
208
+ handover sheets are documents of a parent record: `ref_type` is `waybill`
209
+ (`ref` = shipment ID `shp_…`), `manifest` (manifest batch number) or
210
+ `handover` (handover number). `list` returns each document with its
211
+ `download_path`; `download` returns one file; `merged` returns one PDF that
212
+ merges documents page by page.
213
+
214
+ `merged` sends its parameters as given (the SDK does not filter or reorder):
215
+ without `document_ids` the server merges the active carrier-side documents
216
+ (`sources` defaults to `carrier`; pass `sources="carrier,customer"` to add the
217
+ documents you uploaded) in its default order; `document_ids` (at most 50, no
218
+ duplicates) is merged in the given order and makes the server ignore `types`,
219
+ `sources` and `print_media`. List parameters may be a comma-separated string
220
+ or a list.
221
+
222
+ ```python
223
+ docs = client.doc.documents.list("waybill", "shp_...").data["data"]
224
+ pdf = client.doc.documents.merged("waybill", "shp_...", document_ids=[d["id"] for d in docs])
225
+ customs = client.doc.documents.merged(
226
+ "waybill", "shp_...",
227
+ types=["customs_declaration", "commercial_invoice"],
228
+ sources=["carrier", "customer"],
229
+ )
230
+ ```
231
+
232
+ A stored file answers `302` with a short-lived signed link; the SDK follows
233
+ it without the `Authorization` header (the access token is only sent to your
234
+ API domain). The default transport never follows redirects on its own.
235
+
236
+ ### `reference_no` and safe retries
237
+
238
+ Every shipment entry needs a `reference_no` (non-blank, at most 100
239
+ characters). It is unique per customer among shipments that are not
240
+ cancelled or voided, compared case-insensitively. A second entry with the
241
+ same reference fails with `SHIPMENT_REFERENCE_EXISTS`; when an existing
242
+ shipment holds the reference, the entry also carries that shipment's
243
+ `shipment_id` (not for two duplicate entries in the same batch). Cancelling or voiding a
244
+ shipment frees its reference.
245
+
246
+ That makes a create safe to retry after a network failure: if the first
247
+ attempt reached the server, the retry reports `SHIPMENT_REFERENCE_EXISTS`
248
+ with the existing `shipment_id`. Treat that as "already created" when the
249
+ `shipment_id` is the one you expect. `SHIPMENT_BATCH_ROLLED_BACK` means the
250
+ entry was not created because another entry in the batch hit a concurrent
251
+ conflict; retry it unchanged.
252
+
253
+ ### `ApiResponse.data` typing
254
+
255
+ `data` is the **raw parsed JSON body** — `dict[str, Any] | list[Any] | None`.
256
+ The SDK does not map responses to typed model classes.
257
+
258
+ ### Webhook duplicate vs signature failure
259
+
260
+ ```python
261
+ try:
262
+ event = verifier.verify(headers=req.headers, raw_body=req.body)
263
+ # ... process event
264
+ except FlowabbitWebhookDuplicateEventError as e:
265
+ # Normal idempotent dedup — ACK 200, no alert.
266
+ log.info("duplicate webhook ignored", event_id=e.event_id)
267
+ except FlowabbitWebhookSignatureError as e:
268
+ # Real auth failure — reject + alert.
269
+ log.warning("webhook signature invalid", reason=str(e))
270
+ ```
271
+
272
+ The two exceptions are **siblings**, not parent/child — callers cannot
273
+ accidentally catch a duplicate event as a signature error.
274
+
275
+ `event_type` is read from the signed JSON body (`event_type` field); the
276
+ `X-Flowabbit-Event` header carries the same value for routing before
277
+ verification and is not trusted on its own. Event types are an open set
278
+ (for example `manifest.completed`): handle the ones you know and acknowledge
279
+ the rest.
280
+
281
+ ### `RetryPolicy.max_retries`
282
+
283
+ `max_retries=N` produces **N+1 total attempts** (1 initial + N retries).
284
+ Default is `max_retries=3`. Network errors, 429 and 5xx are retried for
285
+ `GET`, `HEAD`, `DELETE` and `OPTIONS`, and for the `POST` operations whose
286
+ replay cannot repeat an effect (see the Retried column under Operations).
287
+ `POST /tms/shipments` is retried only when every entry carries a non-blank
288
+ `reference_no`; modify and handover item removal are never retried.
289
+
290
+ ### Runtime helpers (exported from `flowabbit.runtime`)
291
+
292
+ | Helper | Purpose |
293
+ | ------------------- | ------------------------------------------------------------------------ |
294
+ | `TokenManager` | OAuth2 client_credentials, lazy fetch, 60s expiry buffer, 401 refresh |
295
+ | `RetryPolicy` | Replay-safe retries only, RFC 9333 Reset > Retry-After > exponential backoff |
296
+ | Typed errors | 5 HTTP status classes; `err.error_code` / `err.message` / `err.request_id` come from the Problem Details `code` / `detail` / `request_id` (missing → `unknown_error` / empty); switch on `err.error_code` for the code catalog |
297
+ | `WebhookVerifier` | Standard Webhooks (`webhook-id` / `webhook-timestamp` / `webhook-signature`, `whsec_` secrets, multi-signature rotation), ±5 min skew, customer-supplied `dedup_hook` (SDK stateless) |
298
+ | `RateLimitInfo` | RFC 9333 `RateLimit-*` + legacy `X-RateLimit-*` parsed off responses |
299
+
300
+ ### Not included
301
+
302
+ - Async / asyncio variant.
303
+ - Distributed token cache.
304
+ - Webhook `event_id` deduplication storage (caller passes `dedup_hook`).
305
+ - Retry of `POST /tms/shipments` when any entry lacks `reference_no`.
306
+
307
+ ## Versioning and releases
308
+
309
+ Versions follow [Semantic Versioning](https://semver.org). Pushing a
310
+ `vX.Y.Z` tag runs the release workflow, which checks that the tag matches
311
+ the `pyproject.toml` version, builds the sdist and wheel and publishes them
312
+ to [PyPI](https://pypi.org/project/flowabbit/) through Trusted Publishing.
313
+ See [CHANGELOG.md](CHANGELOG.md).
314
+
315
+ ## Support
316
+
317
+ Open an issue in this repository:
318
+ https://github.com/flowabbit/flowabbit-python/issues
319
+
320
+ ## Development
321
+
322
+ ```bash
323
+ python -m venv .venv && . .venv/bin/activate
324
+ pip install -e '.[test]'
325
+ pytest
326
+ ```
327
+
328
+ ## License
329
+
330
+ Apache License, Version 2.0. See [LICENSE](LICENSE).