apostra 0.38.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.
- apostra-0.38.0/LICENSE +201 -0
- apostra-0.38.0/PKG-INFO +134 -0
- apostra-0.38.0/README.md +119 -0
- apostra-0.38.0/SKILL.md +29 -0
- apostra-0.38.0/examples/first_value.py +64 -0
- apostra-0.38.0/llms.txt +11 -0
- apostra-0.38.0/pyproject.toml +43 -0
- apostra-0.38.0/src/apostra/__init__.py +27 -0
- apostra-0.38.0/src/apostra/_version.py +3 -0
- apostra-0.38.0/src/apostra/client.py +1078 -0
- apostra-0.38.0/src/apostra/json_value.py +3 -0
- apostra-0.38.0/src/apostra/models.py +19955 -0
- apostra-0.38.0/src/apostra/operations.json +1335 -0
- apostra-0.38.0/src/apostra/py.typed +0 -0
- apostra-0.38.0/src/apostra/transport.py +1014 -0
- apostra-0.38.0/tests/adcp_interop_invalid.py +5 -0
- apostra-0.38.0/tests/adcp_interop_valid.py +95 -0
- apostra-0.38.0/tests/fixtures/v3-vectors.json +187 -0
- apostra-0.38.0/tests/test_transport.py +1008 -0
- apostra-0.38.0/tests/types_invalid.py +16 -0
- apostra-0.38.0/tests/types_valid.py +32 -0
- apostra-0.38.0/uv.lock +1571 -0
apostra-0.38.0/LICENSE
ADDED
|
@@ -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 Scope3 PBC
|
|
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.
|
apostra-0.38.0/PKG-INFO
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: apostra
|
|
3
|
+
Version: 0.38.0
|
|
4
|
+
Summary: The official Apostra V3 HTTP SDK
|
|
5
|
+
Project-URL: Source, https://github.com/apostra-public/apostra/tree/main/sdk/python
|
|
6
|
+
Project-URL: Documentation, https://docs.apostra.com/v2/sdk
|
|
7
|
+
Project-URL: Changelog, https://docs.apostra.com/v2/changelog
|
|
8
|
+
Author: Scope3 PBC
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Requires-Python: >=3.11
|
|
12
|
+
Requires-Dist: httpx<0.29,>=0.28.1
|
|
13
|
+
Requires-Dist: typing-extensions<5,>=4.15
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
|
|
16
|
+
# Apostra Python SDK
|
|
17
|
+
|
|
18
|
+
Typed synchronous and asynchronous calls to the public V3 HTTP API. Python 3.11+.
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
python -m pip install apostra
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Start with the [SDK quickstart](https://docs.apostra.com/v3/sdk-quickstart).
|
|
25
|
+
It covers account discovery, a campaign launch preview and confirmation, and
|
|
26
|
+
delivery reporting. The [runnable synthetic-seller
|
|
27
|
+
example](https://github.com/apostra-public/apostra/blob/main/sdk/python/examples/first_value.py)
|
|
28
|
+
is in the SDK source checkout. It previews by default and only confirms a
|
|
29
|
+
launch when `APOSTRA_CONFIRM_LAUNCH=true` is set deliberately.
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
from apostra import Apostra
|
|
33
|
+
api = Apostra()
|
|
34
|
+
try:
|
|
35
|
+
status = api.get_status()
|
|
36
|
+
finally:
|
|
37
|
+
api.close()
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Models in `apostra.models` are typed wire dictionaries: keep the contract's
|
|
41
|
+
field names, including camelCase keys. Methods use snake_case and return the
|
|
42
|
+
envelope's `data`. Both mypy and pyright check inputs, results and recursive
|
|
43
|
+
JSON types. Runtime schema constraints remain enforced by the server.
|
|
44
|
+
|
|
45
|
+
Every generated method also has a `_with_response` variant, such as
|
|
46
|
+
`get_status_with_response`. It returns a successful response dictionary with
|
|
47
|
+
`data`, `request_id`, `headers` and `status`, so support tools can retain
|
|
48
|
+
`x-request-id` and response headers without dispatching by a wire
|
|
49
|
+
operation name.
|
|
50
|
+
|
|
51
|
+
The client reads `APOSTRA_API_KEY`, `APOSTRA_ACCOUNT_ID` and
|
|
52
|
+
`APOSTRA_BASE_URL` by default. Explicit constructor options override those
|
|
53
|
+
values. Use `access_token` for an existing REST/M2M bearer token or
|
|
54
|
+
`token_provider` for application-managed refresh. `m2m_token_provider` and
|
|
55
|
+
`m2m_token_provider_async` acquire and cache server-side client-credentials
|
|
56
|
+
tokens, refresh 60 seconds before expiry, and share a concurrent refresh. The
|
|
57
|
+
async client requires the async provider. Supply exactly one source. Never
|
|
58
|
+
expose keys or client secrets in browser code, URLs or logs. Credentials are
|
|
59
|
+
neither persisted nor included in exception strings. M2M token refreshes have a
|
|
60
|
+
30-second deadline by default; pass `timeout` to override it.
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
import os
|
|
64
|
+
|
|
65
|
+
from apostra import Apostra, m2m_token_provider
|
|
66
|
+
|
|
67
|
+
api = Apostra(token_provider=m2m_token_provider(
|
|
68
|
+
client_id=os.environ['APOSTRA_CLIENT_ID'],
|
|
69
|
+
client_secret=os.environ['APOSTRA_CLIENT_SECRET'],
|
|
70
|
+
scope='interchange:read',
|
|
71
|
+
))
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
`ApostraError` exposes `status`, `code`, `recovery`, `retry_after`, `retryable`,
|
|
75
|
+
`error` and `request_id`. Catch `RateLimitError`, `ValidationError`, or another
|
|
76
|
+
typed exception instead of parsing exception text. Read calls take
|
|
77
|
+
`account_id` and `timeout` overrides; write calls also require a caller-owned
|
|
78
|
+
`idempotency_key`, which the SDK sends as `Idempotency-Key` without creating or
|
|
79
|
+
replacing it. Account targeting must match the account resolved by
|
|
80
|
+
authentication. Default timeout: 30 seconds. Transient network, 429 and 5xx
|
|
81
|
+
failures retry twice by default with full-jitter backoff; set `max_retries=0`
|
|
82
|
+
to opt out. Reads retry automatically. Writes reuse only their caller-owned
|
|
83
|
+
idempotency key, and the server's `retry_after` is a minimum delay. HTTP
|
|
84
|
+
redirects are not followed. `AsyncApostra` supports asyncio task cancellation;
|
|
85
|
+
cancelling HTTP does not undo server-side work. Clients close only HTTP clients
|
|
86
|
+
they own; callers close injected clients.
|
|
87
|
+
Async timeouts include token acquisition and HTTP. A synchronous provider runs
|
|
88
|
+
behind the same caller deadline, so a blocked provider raises `TimeoutError`
|
|
89
|
+
without sending an HTTP request. Python cannot forcibly interrupt blocked work,
|
|
90
|
+
so at most one sync request can remain in flight per client.
|
|
91
|
+
An HTTP `202` raises `InFlightReceiptError`, not a completed operation value.
|
|
92
|
+
It exposes the request ID and numeric `Retry-After` while the V3 receipt schema
|
|
93
|
+
and its read-only endpoint are pending. Keep the original operation key. Use
|
|
94
|
+
`settle` (or `settle_async`) to replay that exact operation until it completes:
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
from apostra import settle
|
|
98
|
+
|
|
99
|
+
key = 'preview-123'
|
|
100
|
+
result = settle(
|
|
101
|
+
lambda: api.save_ask(input, idempotency_key=key),
|
|
102
|
+
timeout=30,
|
|
103
|
+
)
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
response = api.get_status_with_response()
|
|
108
|
+
data = response['data']
|
|
109
|
+
request_id = response['request_id']
|
|
110
|
+
correlation_id = response['headers']['x-request-id']
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
`paginate`, `paginate_async` and `poll` accept typed callbacks, leaving exact
|
|
114
|
+
cursor/status rules to the caller. `poll` requires a finite timeout.
|
|
115
|
+
Async helper cancellation propagates into the awaited read. A failed read
|
|
116
|
+
ends pagination or polling; neither helper retries it.
|
|
117
|
+
`verify_webhook` validates duplicate-preserving V3 webhook headers, the raw
|
|
118
|
+
body, the five-minute delivery window, and a rotating key map before you parse
|
|
119
|
+
JSON. Provide every raw occurrence of `signature`, `timestamp`, and
|
|
120
|
+
`deliveryId`; do not flatten duplicate headers or log secrets.
|
|
121
|
+
|
|
122
|
+
`open_handoff(url, opener=None)` returns the supplied HTTPS URL in headless
|
|
123
|
+
code. An explicit opener can display a URL actually returned by the API.
|
|
124
|
+
There is no inferred URL, embedded UI, login, wait/resume, or byte-upload helper.
|
|
125
|
+
Those need a public contract. `upload_creative_asset`
|
|
126
|
+
returns the current typed human task and fallback URL.
|
|
127
|
+
`get_handoff(result)` returns a supported human action with its `kind`, `url`,
|
|
128
|
+
`expiresAt` and `resume` instructions, or `None`. Pass it to
|
|
129
|
+
`open_handoff(handoff, opener=None)` to return the supplied HTTPS URL in
|
|
130
|
+
headless code or display it with an explicit opener. Opening or closing the
|
|
131
|
+
browser is not completion: follow `resume` and read the affected object before
|
|
132
|
+
continuing. The SDK never infers a URL or embeds a login flow.
|
|
133
|
+
|
|
134
|
+
Source and releases: https://github.com/apostra-public/apostra
|
apostra-0.38.0/README.md
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# Apostra Python SDK
|
|
2
|
+
|
|
3
|
+
Typed synchronous and asynchronous calls to the public V3 HTTP API. Python 3.11+.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
python -m pip install apostra
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Start with the [SDK quickstart](https://docs.apostra.com/v3/sdk-quickstart).
|
|
10
|
+
It covers account discovery, a campaign launch preview and confirmation, and
|
|
11
|
+
delivery reporting. The [runnable synthetic-seller
|
|
12
|
+
example](https://github.com/apostra-public/apostra/blob/main/sdk/python/examples/first_value.py)
|
|
13
|
+
is in the SDK source checkout. It previews by default and only confirms a
|
|
14
|
+
launch when `APOSTRA_CONFIRM_LAUNCH=true` is set deliberately.
|
|
15
|
+
|
|
16
|
+
```python
|
|
17
|
+
from apostra import Apostra
|
|
18
|
+
api = Apostra()
|
|
19
|
+
try:
|
|
20
|
+
status = api.get_status()
|
|
21
|
+
finally:
|
|
22
|
+
api.close()
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Models in `apostra.models` are typed wire dictionaries: keep the contract's
|
|
26
|
+
field names, including camelCase keys. Methods use snake_case and return the
|
|
27
|
+
envelope's `data`. Both mypy and pyright check inputs, results and recursive
|
|
28
|
+
JSON types. Runtime schema constraints remain enforced by the server.
|
|
29
|
+
|
|
30
|
+
Every generated method also has a `_with_response` variant, such as
|
|
31
|
+
`get_status_with_response`. It returns a successful response dictionary with
|
|
32
|
+
`data`, `request_id`, `headers` and `status`, so support tools can retain
|
|
33
|
+
`x-request-id` and response headers without dispatching by a wire
|
|
34
|
+
operation name.
|
|
35
|
+
|
|
36
|
+
The client reads `APOSTRA_API_KEY`, `APOSTRA_ACCOUNT_ID` and
|
|
37
|
+
`APOSTRA_BASE_URL` by default. Explicit constructor options override those
|
|
38
|
+
values. Use `access_token` for an existing REST/M2M bearer token or
|
|
39
|
+
`token_provider` for application-managed refresh. `m2m_token_provider` and
|
|
40
|
+
`m2m_token_provider_async` acquire and cache server-side client-credentials
|
|
41
|
+
tokens, refresh 60 seconds before expiry, and share a concurrent refresh. The
|
|
42
|
+
async client requires the async provider. Supply exactly one source. Never
|
|
43
|
+
expose keys or client secrets in browser code, URLs or logs. Credentials are
|
|
44
|
+
neither persisted nor included in exception strings. M2M token refreshes have a
|
|
45
|
+
30-second deadline by default; pass `timeout` to override it.
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
import os
|
|
49
|
+
|
|
50
|
+
from apostra import Apostra, m2m_token_provider
|
|
51
|
+
|
|
52
|
+
api = Apostra(token_provider=m2m_token_provider(
|
|
53
|
+
client_id=os.environ['APOSTRA_CLIENT_ID'],
|
|
54
|
+
client_secret=os.environ['APOSTRA_CLIENT_SECRET'],
|
|
55
|
+
scope='interchange:read',
|
|
56
|
+
))
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
`ApostraError` exposes `status`, `code`, `recovery`, `retry_after`, `retryable`,
|
|
60
|
+
`error` and `request_id`. Catch `RateLimitError`, `ValidationError`, or another
|
|
61
|
+
typed exception instead of parsing exception text. Read calls take
|
|
62
|
+
`account_id` and `timeout` overrides; write calls also require a caller-owned
|
|
63
|
+
`idempotency_key`, which the SDK sends as `Idempotency-Key` without creating or
|
|
64
|
+
replacing it. Account targeting must match the account resolved by
|
|
65
|
+
authentication. Default timeout: 30 seconds. Transient network, 429 and 5xx
|
|
66
|
+
failures retry twice by default with full-jitter backoff; set `max_retries=0`
|
|
67
|
+
to opt out. Reads retry automatically. Writes reuse only their caller-owned
|
|
68
|
+
idempotency key, and the server's `retry_after` is a minimum delay. HTTP
|
|
69
|
+
redirects are not followed. `AsyncApostra` supports asyncio task cancellation;
|
|
70
|
+
cancelling HTTP does not undo server-side work. Clients close only HTTP clients
|
|
71
|
+
they own; callers close injected clients.
|
|
72
|
+
Async timeouts include token acquisition and HTTP. A synchronous provider runs
|
|
73
|
+
behind the same caller deadline, so a blocked provider raises `TimeoutError`
|
|
74
|
+
without sending an HTTP request. Python cannot forcibly interrupt blocked work,
|
|
75
|
+
so at most one sync request can remain in flight per client.
|
|
76
|
+
An HTTP `202` raises `InFlightReceiptError`, not a completed operation value.
|
|
77
|
+
It exposes the request ID and numeric `Retry-After` while the V3 receipt schema
|
|
78
|
+
and its read-only endpoint are pending. Keep the original operation key. Use
|
|
79
|
+
`settle` (or `settle_async`) to replay that exact operation until it completes:
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
from apostra import settle
|
|
83
|
+
|
|
84
|
+
key = 'preview-123'
|
|
85
|
+
result = settle(
|
|
86
|
+
lambda: api.save_ask(input, idempotency_key=key),
|
|
87
|
+
timeout=30,
|
|
88
|
+
)
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
response = api.get_status_with_response()
|
|
93
|
+
data = response['data']
|
|
94
|
+
request_id = response['request_id']
|
|
95
|
+
correlation_id = response['headers']['x-request-id']
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
`paginate`, `paginate_async` and `poll` accept typed callbacks, leaving exact
|
|
99
|
+
cursor/status rules to the caller. `poll` requires a finite timeout.
|
|
100
|
+
Async helper cancellation propagates into the awaited read. A failed read
|
|
101
|
+
ends pagination or polling; neither helper retries it.
|
|
102
|
+
`verify_webhook` validates duplicate-preserving V3 webhook headers, the raw
|
|
103
|
+
body, the five-minute delivery window, and a rotating key map before you parse
|
|
104
|
+
JSON. Provide every raw occurrence of `signature`, `timestamp`, and
|
|
105
|
+
`deliveryId`; do not flatten duplicate headers or log secrets.
|
|
106
|
+
|
|
107
|
+
`open_handoff(url, opener=None)` returns the supplied HTTPS URL in headless
|
|
108
|
+
code. An explicit opener can display a URL actually returned by the API.
|
|
109
|
+
There is no inferred URL, embedded UI, login, wait/resume, or byte-upload helper.
|
|
110
|
+
Those need a public contract. `upload_creative_asset`
|
|
111
|
+
returns the current typed human task and fallback URL.
|
|
112
|
+
`get_handoff(result)` returns a supported human action with its `kind`, `url`,
|
|
113
|
+
`expiresAt` and `resume` instructions, or `None`. Pass it to
|
|
114
|
+
`open_handoff(handoff, opener=None)` to return the supplied HTTPS URL in
|
|
115
|
+
headless code or display it with an explicit opener. Opening or closing the
|
|
116
|
+
browser is not completion: follow `resume` and read the affected object before
|
|
117
|
+
continuing. The SDK never infers a URL or embeds a login flow.
|
|
118
|
+
|
|
119
|
+
Source and releases: https://github.com/apostra-public/apostra
|
apostra-0.38.0/SKILL.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: apostra-sdk
|
|
3
|
+
description: Choose the Apostra Python SDK method for a coding task, then read the public documentation for the current contract.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Apostra Python SDK
|
|
7
|
+
|
|
8
|
+
Read the [SDK guide](https://docs.apostra.com/v2/sdk), [V3 HTTP API
|
|
9
|
+
guide](https://docs.apostra.com/v3/http-api), and [authentication
|
|
10
|
+
guide](https://docs.apostra.com/v3/authentication) before relying on an
|
|
11
|
+
operation. They are the source of truth for inputs, results, permissions, and
|
|
12
|
+
behaviour.
|
|
13
|
+
|
|
14
|
+
## Job-to-method map
|
|
15
|
+
|
|
16
|
+
| Job | Method |
|
|
17
|
+
| --- | --- |
|
|
18
|
+
| Check the resolved account | `get_status` |
|
|
19
|
+
| Discover objects or read one object | `search`, `get` |
|
|
20
|
+
| Create, update, preview, or confirm a campaign | `save_campaign` |
|
|
21
|
+
| Read delivery | `get_delivery` |
|
|
22
|
+
| Inspect a successful call's request ID or headers | `get_status_with_response` (and the matching `_with_response` method) |
|
|
23
|
+
| Handle a human handoff and resume safely | `get_handoff`, then `open_handoff` |
|
|
24
|
+
| Authenticate a deployed backend with M2M OAuth | `m2m_token_provider` or `m2m_token_provider_async` |
|
|
25
|
+
| Verify an inbound V3 webhook | `verify_webhook` |
|
|
26
|
+
|
|
27
|
+
Use the generated types and the current documentation to construct requests. Do
|
|
28
|
+
not infer fields, permissions, lifecycle transitions, or URL formats from this
|
|
29
|
+
map.
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from uuid import uuid4
|
|
3
|
+
|
|
4
|
+
from apostra import Apostra
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def required(name: str) -> str:
|
|
8
|
+
value = os.environ.get(name)
|
|
9
|
+
if value is None or value == '':
|
|
10
|
+
raise RuntimeError(f'{name} is required')
|
|
11
|
+
return value
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
with Apostra(
|
|
15
|
+
api_key=required('APOSTRA_API_KEY'),
|
|
16
|
+
account_id=os.environ.get('APOSTRA_ACCOUNT_ID'),
|
|
17
|
+
base_url=os.environ.get('APOSTRA_BASE_URL', 'https://api.apostra.com/api/v3'),
|
|
18
|
+
) as api:
|
|
19
|
+
campaign_id = required('APOSTRA_CAMPAIGN_ID')
|
|
20
|
+
|
|
21
|
+
# Verify the credential and discover the resolved account before any write.
|
|
22
|
+
status = api.get_status({})
|
|
23
|
+
if not status.get('account'):
|
|
24
|
+
raise RuntimeError('The credential did not resolve an account')
|
|
25
|
+
|
|
26
|
+
# A unique key belongs to this exact preview request. Reuse it only to retry
|
|
27
|
+
# the same request after an uncertain response.
|
|
28
|
+
preview_key = str(uuid4())
|
|
29
|
+
preview = api.save_campaign(
|
|
30
|
+
{
|
|
31
|
+
'campaignId': campaign_id,
|
|
32
|
+
'desiredPhase': 'active',
|
|
33
|
+
'idempotencyKey': preview_key,
|
|
34
|
+
},
|
|
35
|
+
idempotency_key=preview_key,
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
# Inspect `preview` before confirming. Confirmation is deliberately opt-in
|
|
39
|
+
# so running the sample against the synthetic seller remains a preview by default.
|
|
40
|
+
if os.environ.get('APOSTRA_CONFIRM_LAUNCH') == 'true':
|
|
41
|
+
confirm_key = str(uuid4())
|
|
42
|
+
api.save_campaign(
|
|
43
|
+
{
|
|
44
|
+
'campaignId': campaign_id,
|
|
45
|
+
'desiredPhase': 'active',
|
|
46
|
+
'confirmLaunch': True,
|
|
47
|
+
'idempotencyKey': confirm_key,
|
|
48
|
+
},
|
|
49
|
+
idempotency_key=confirm_key,
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
delivery = api.get_delivery(
|
|
53
|
+
{
|
|
54
|
+
'report': 'campaign_delivery',
|
|
55
|
+
'filters': {'campaignId': campaign_id},
|
|
56
|
+
'range': {
|
|
57
|
+
'startDate': required('APOSTRA_START_DATE'),
|
|
58
|
+
'endDate': required('APOSTRA_END_DATE'),
|
|
59
|
+
},
|
|
60
|
+
'limit': 100,
|
|
61
|
+
}
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
_ = preview, delivery
|
apostra-0.38.0/llms.txt
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Apostra Python SDK
|
|
2
|
+
|
|
3
|
+
Read `SKILL.md` in this package before implementing an Apostra task.
|
|
4
|
+
|
|
5
|
+
- SDK guide: https://docs.apostra.com/v2/sdk
|
|
6
|
+
- V3 HTTP contract: https://docs.apostra.com/v3/http-api
|
|
7
|
+
- Authentication: https://docs.apostra.com/v3/authentication
|
|
8
|
+
- Complete documentation corpus: https://docs.apostra.com/llms-full.txt
|
|
9
|
+
|
|
10
|
+
The public documentation is the source of truth for operation inputs, results,
|
|
11
|
+
permissions, and behaviour.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling==1.27.0"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "apostra"
|
|
7
|
+
version = "0.38.0"
|
|
8
|
+
description = "The official Apostra V3 HTTP SDK"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = "Apache-2.0"
|
|
12
|
+
authors = [{name = "Scope3 PBC"}]
|
|
13
|
+
dependencies = ["httpx>=0.28.1,<0.29", "typing-extensions>=4.15,<5"]
|
|
14
|
+
|
|
15
|
+
[project.urls]
|
|
16
|
+
Source = "https://github.com/apostra-public/apostra/tree/main/sdk/python"
|
|
17
|
+
Documentation = "https://docs.apostra.com/v2/sdk"
|
|
18
|
+
Changelog = "https://docs.apostra.com/v2/changelog"
|
|
19
|
+
|
|
20
|
+
[dependency-groups]
|
|
21
|
+
dev = ["mypy==1.20.0", "pyright==1.1.408", "ruff==0.12.12", "build==1.3.0"]
|
|
22
|
+
interop = ["adcp==8.0.0b15"]
|
|
23
|
+
|
|
24
|
+
[tool.hatch.build.targets.wheel]
|
|
25
|
+
packages = ["src/apostra"]
|
|
26
|
+
|
|
27
|
+
[tool.hatch.build.targets.wheel.force-include]
|
|
28
|
+
"SKILL.md" = "src/apostra/SKILL.md"
|
|
29
|
+
"llms.txt" = "src/apostra/llms.txt"
|
|
30
|
+
|
|
31
|
+
[tool.hatch.build.targets.sdist]
|
|
32
|
+
only-include = ["src/apostra", "tests", "examples", "LICENSE", "README.md", "SKILL.md", "llms.txt", "pyproject.toml", "uv.lock"]
|
|
33
|
+
|
|
34
|
+
[tool.mypy]
|
|
35
|
+
strict = true
|
|
36
|
+
|
|
37
|
+
[tool.pyright]
|
|
38
|
+
include = ["src", "tests/types_valid.py", "tests/test_transport.py", "examples/first_value.py"]
|
|
39
|
+
typeCheckingMode = "strict"
|
|
40
|
+
pythonVersion = "3.11"
|
|
41
|
+
|
|
42
|
+
[tool.ruff]
|
|
43
|
+
target-version = "py311"
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from ._version import __version__ as __version__
|
|
2
|
+
from .client import Apostra as Apostra, AsyncApostra as AsyncApostra
|
|
3
|
+
from .transport import (
|
|
4
|
+
ApostraError as ApostraError,
|
|
5
|
+
AuthenticationError as AuthenticationError,
|
|
6
|
+
ConnectionError as ConnectionError,
|
|
7
|
+
ConflictError as ConflictError,
|
|
8
|
+
InFlightReceiptError as InFlightReceiptError,
|
|
9
|
+
m2m_token_provider as m2m_token_provider,
|
|
10
|
+
m2m_token_provider_async as m2m_token_provider_async,
|
|
11
|
+
NotFoundError as NotFoundError,
|
|
12
|
+
PermissionError as PermissionError,
|
|
13
|
+
ProtocolError as ProtocolError,
|
|
14
|
+
RateLimitError as RateLimitError,
|
|
15
|
+
ResponseDetails as ResponseDetails,
|
|
16
|
+
TimeoutError as TimeoutError,
|
|
17
|
+
UnsupportedCapabilityError as UnsupportedCapabilityError,
|
|
18
|
+
ValidationError as ValidationError,
|
|
19
|
+
verify_webhook as verify_webhook,
|
|
20
|
+
get_handoff as get_handoff,
|
|
21
|
+
open_handoff as open_handoff,
|
|
22
|
+
paginate as paginate,
|
|
23
|
+
paginate_async as paginate_async,
|
|
24
|
+
poll as poll,
|
|
25
|
+
settle as settle,
|
|
26
|
+
settle_async as settle_async,
|
|
27
|
+
)
|