rasket 0.4.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.
- rasket-0.4.0/.gitignore +57 -0
- rasket-0.4.0/CHANGELOG.md +152 -0
- rasket-0.4.0/LICENSE +21 -0
- rasket-0.4.0/PKG-INFO +172 -0
- rasket-0.4.0/README.md +148 -0
- rasket-0.4.0/pyproject.toml +78 -0
- rasket-0.4.0/src/rasket/__init__.py +55 -0
- rasket-0.4.0/src/rasket/_client.py +55 -0
- rasket-0.4.0/src/rasket/_errors.py +151 -0
- rasket-0.4.0/src/rasket/_http.py +515 -0
- rasket-0.4.0/src/rasket/_replay.py +35 -0
- rasket-0.4.0/src/rasket/_types.py +6396 -0
- rasket-0.4.0/src/rasket/_version.py +7 -0
- rasket-0.4.0/src/rasket/py.typed +0 -0
- rasket-0.4.0/src/rasket/resources/__init__.py +90 -0
- rasket-0.4.0/src/rasket/resources/ai.py +137 -0
- rasket-0.4.0/src/rasket/resources/api_keys.py +56 -0
- rasket-0.4.0/src/rasket/resources/automations.py +150 -0
- rasket-0.4.0/src/rasket/resources/autopilot.py +227 -0
- rasket-0.4.0/src/rasket/resources/batch.py +34 -0
- rasket-0.4.0/src/rasket/resources/billing.py +113 -0
- rasket-0.4.0/src/rasket/resources/broadcasts.py +168 -0
- rasket-0.4.0/src/rasket/resources/contacts.py +369 -0
- rasket-0.4.0/src/rasket/resources/domains.py +260 -0
- rasket-0.4.0/src/rasket/resources/emails.py +252 -0
- rasket-0.4.0/src/rasket/resources/events.py +88 -0
- rasket-0.4.0/src/rasket/resources/inbox.py +271 -0
- rasket-0.4.0/src/rasket/resources/limits.py +44 -0
- rasket-0.4.0/src/rasket/resources/logs.py +34 -0
- rasket-0.4.0/src/rasket/resources/oauth.py +49 -0
- rasket-0.4.0/src/rasket/resources/segments.py +124 -0
- rasket-0.4.0/src/rasket/resources/sms.py +271 -0
- rasket-0.4.0/src/rasket/resources/stores.py +110 -0
- rasket-0.4.0/src/rasket/resources/suppressions.py +82 -0
- rasket-0.4.0/src/rasket/resources/team.py +136 -0
- rasket-0.4.0/src/rasket/resources/templates.py +234 -0
- rasket-0.4.0/src/rasket/resources/topics.py +61 -0
- rasket-0.4.0/src/rasket/resources/webhooks.py +188 -0
- rasket-0.4.0/src/rasket/webhooks.py +166 -0
rasket-0.4.0/.gitignore
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# dependencies
|
|
2
|
+
node_modules/
|
|
3
|
+
|
|
4
|
+
# build output
|
|
5
|
+
dist/
|
|
6
|
+
.next/
|
|
7
|
+
out/
|
|
8
|
+
*.tsbuildinfo
|
|
9
|
+
|
|
10
|
+
# task/tool caches
|
|
11
|
+
.turbo/
|
|
12
|
+
.vercel/
|
|
13
|
+
coverage/
|
|
14
|
+
.eslintcache
|
|
15
|
+
.swc/
|
|
16
|
+
|
|
17
|
+
apps/web/.gitignore
|
|
18
|
+
|
|
19
|
+
# local runtime state (LocalObjectStore, fake DNS zones, local KMS material)
|
|
20
|
+
.data/
|
|
21
|
+
|
|
22
|
+
# environment: names live in .env.example, values never leave the machine
|
|
23
|
+
.env
|
|
24
|
+
.env.*.local
|
|
25
|
+
|
|
26
|
+
# os / editor
|
|
27
|
+
.DS_Store
|
|
28
|
+
*.log
|
|
29
|
+
|
|
30
|
+
# terraform (infrastructure/aws): state, the provider cache, the outputs dump and any tfvars
|
|
31
|
+
# holding real values. `.terraform.lock.hcl` and `*.tfvars.example` are committed on purpose —
|
|
32
|
+
# the lock so CI resolves the same provider builds, the example so the root is reproducible.
|
|
33
|
+
# `*.tfvars.example` does not match `*.tfvars`, which only matches a name ending in `.tfvars`.
|
|
34
|
+
infrastructure/aws/.terraform/
|
|
35
|
+
infrastructure/aws/*.tfstate
|
|
36
|
+
infrastructure/aws/*.tfstate.*
|
|
37
|
+
infrastructure/aws/*.tfvars
|
|
38
|
+
infrastructure/aws/outputs.json
|
|
39
|
+
|
|
40
|
+
# The agent skill, copied from skills/ by apps/web's `prebuild` (scripts/copy-skills.mjs, A115) so
|
|
41
|
+
# the docs site can serve it. Ignored here rather than in apps/web/.gitignore, which is itself
|
|
42
|
+
# ignored above (the Workflow SDK writes it), so an entry there would never be committed.
|
|
43
|
+
apps/web/public/skills/
|
|
44
|
+
|
|
45
|
+
# the Python client (packages/sdk-python): its virtualenv, build output and tool caches
|
|
46
|
+
packages/sdk-python/.venv/
|
|
47
|
+
packages/sdk-python/dist/
|
|
48
|
+
packages/sdk-python/**/__pycache__/
|
|
49
|
+
packages/sdk-python/.mypy_cache/
|
|
50
|
+
packages/sdk-python/.pytest_cache/
|
|
51
|
+
packages/sdk-python/.ruff_cache/
|
|
52
|
+
|
|
53
|
+
# the tarball publish-sdk-node.yml packs with `test:pack --out out` and publishes
|
|
54
|
+
out/
|
|
55
|
+
|
|
56
|
+
# REV-01: the revenue backfill's resume cursor (scripts/billing/backfill-revenue.ts).
|
|
57
|
+
.revenue-backfill.json
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to the `rasket` Python package are recorded here. The format follows
|
|
4
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/); versions follow
|
|
5
|
+
[Semantic Versioning](https://semver.org/).
|
|
6
|
+
|
|
7
|
+
## Unreleased
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- `rasket.ai.draft_campaigns`: three campaign email drafts from a description, each a different
|
|
12
|
+
direction, checked and scored; nothing is saved. Each attempt waits at least 270 s, since a run
|
|
13
|
+
can take minutes (a client `timeout` that is longer still wins).
|
|
14
|
+
- `rasket.stores.tracking_check`: looks for `rasket.js` on a website store's site and answers the
|
|
15
|
+
four rows the dashboard's Website tracking card shows (snippet, product views, cart updates,
|
|
16
|
+
checkouts).
|
|
17
|
+
- `rasket.segments.add_contacts` and `remove_contacts`: put up to 100 contacts in a segment or
|
|
18
|
+
take them out at once, all-or-nothing.
|
|
19
|
+
- `rasket.segments.update` takes an optional `filter`: a segment's rule can now be changed
|
|
20
|
+
(`None` leaves only the people added by hand). `rasket.segments.preview` takes an optional
|
|
21
|
+
`segment_id`.
|
|
22
|
+
- `rasket.sms.senders.cancel_registration`: withdraws a number's registration from the carriers
|
|
23
|
+
and leaves it unsubmitted; the number is kept. `rasket.sms.senders.refresh` with a `business`
|
|
24
|
+
or `messages` block sends it again. The sender's `registration` carries `canceled_at`.
|
|
25
|
+
- `rasket.sms.senders.update`: renames a number (`name`, `None` removes it) and makes an `active`
|
|
26
|
+
number the default for the countries it reaches (`is_default: True`).
|
|
27
|
+
`rasket.sms.senders.create` takes an optional `name`; the sender carries `name` and
|
|
28
|
+
`default_for`.
|
|
29
|
+
- `rasket.autopilot`: `settings.get` and `settings.update` read and change Autopilot's
|
|
30
|
+
settings, and `proposals.list`, `proposals.get`, `proposals.approve` and `proposals.skip` work
|
|
31
|
+
through the campaigns it proposes. Webhook types gain `autopilot.proposal.created`,
|
|
32
|
+
`.approved`, `.skipped`, `.expired` and `.sent`.
|
|
33
|
+
- `rasket.autopilot.playbook`: `get` reads what Autopilot learned from the store's results and
|
|
34
|
+
the edits made before approving; `use`, `dismiss`, `restore` and `reset` are an admin's
|
|
35
|
+
decisions on it.
|
|
36
|
+
- `rasket.autopilot.kinds`: `list` shows whether each kind of campaign has earned sending on its
|
|
37
|
+
own, and `update` puts a `ready` kind on Auto or takes it off. `proposals.cancel` cancels a
|
|
38
|
+
scheduled proposal until 30 minutes before its send. `approval_mode="earned"` is accepted.
|
|
39
|
+
|
|
40
|
+
### Changed
|
|
41
|
+
|
|
42
|
+
- `rasket.templates.saved_blocks.list` and `rasket.limits.requests.list` take an optional `query`
|
|
43
|
+
(`limit`, `after`, `before`) and page: `has_more` is now true when there is more, and `after` the last id reaches
|
|
44
|
+
it. `GET /saved-blocks` answers 100 blocks a page by default (it answered up to 500 on one page,
|
|
45
|
+
with `has_more: false`).
|
|
46
|
+
- `rasket.contacts.segments.remove` and `rasket.segments.remove_contacts` take a contact out of a
|
|
47
|
+
segment even when the segment's filter matches it; it stays out until it is added back.
|
|
48
|
+
|
|
49
|
+
## 0.4.0 — 2026-10-19
|
|
50
|
+
|
|
51
|
+
Not published yet: the owner publishes it once the SMS API is live.
|
|
52
|
+
|
|
53
|
+
### Added
|
|
54
|
+
|
|
55
|
+
- `rasket.sms`: texts to US and Canadian phones, the same twenty methods as the Node client —
|
|
56
|
+
`send` and `batch` (with `idempotency_key`), `estimate`, `list`, `get`, `update`, `cancel`,
|
|
57
|
+
`events.list`, `received`, `senders` and `verified_phones`. The text field is `text`; money is a
|
|
58
|
+
decimal string in dollars.
|
|
59
|
+
- `rasket.contacts.sms_consent.update`: set a contact's SMS consent, with proof.
|
|
60
|
+
- `429 sms_quota_exceeded` is not retried.
|
|
61
|
+
- The error body's `details.reason` gains `sms_policy`, with `details.policy` naming the SMS rule
|
|
62
|
+
that refused a text (SMS-12).
|
|
63
|
+
|
|
64
|
+
## 0.3.0 — 2026-10-15
|
|
65
|
+
|
|
66
|
+
The first version published to PyPI.
|
|
67
|
+
|
|
68
|
+
### Added
|
|
69
|
+
|
|
70
|
+
- Store events: `events.send` takes one of the eight `store:` events (`"store:checkout.started"`,
|
|
71
|
+
`"store:order.placed"`, …) with `anonymous_id`, `idempotency_key` and `occurred_at`;
|
|
72
|
+
`events.identify` ties a browser's `rsk_aid` to a contact. `stores` manages the publishable keys
|
|
73
|
+
`rasket.js` sends with from a website.
|
|
74
|
+
- `subscription_status` on a contact (`contacts.get`, `contacts.list`, segment members) and accepted
|
|
75
|
+
by `contacts.create` and `contacts.update`: `"subscribed"`, `"unsubscribed"` or
|
|
76
|
+
`"never_subscribed"` (a contact another platform held without marketing consent; transactional
|
|
77
|
+
email only). `unsubscribed` keeps its meaning and is `True` for both of the last two. A consent
|
|
78
|
+
record's `action` may now be `"imported_not_subscribed"`.
|
|
79
|
+
- `rasket.inbox`: the support Inbox's shared channels, never a personal mailbox — `channels`,
|
|
80
|
+
`labels`, `folders`, `conversations` (with `messages`, `notes` and `attachments`) and `search`,
|
|
81
|
+
the same fifteen methods as the Node client. An API key needs Inbox access; an OAuth token needs
|
|
82
|
+
`inbox:read` or `inbox:write`.
|
|
83
|
+
- `RasketResponse.etag`, set when the API sends an `ETag`, and
|
|
84
|
+
`inbox.conversations.update(id, body, if_match=...)` to refuse a change made since.
|
|
85
|
+
- `rasket.broadcasts.save_as_template(id)`: keep a broadcast's subject, HTML and text as a new
|
|
86
|
+
published template. Each call makes a new template.
|
|
87
|
+
- `rasket.templates.starters.list({"goal": …})`: list one goal of the starter library. Every starter now
|
|
88
|
+
carries `goal`, `kind` and `tags`.
|
|
89
|
+
|
|
90
|
+
- `rasket.templates.saved_blocks`: `create`, `list`, `get`, `update` and `remove` a project's saved
|
|
91
|
+
blocks — a header, a footer or any block its visual templates place by reference. `update` with
|
|
92
|
+
a new `document` publishes it to every template whose published version uses the block.
|
|
93
|
+
- `rasket.broadcasts.checks(id)` and `rasket.templates.checks(id, {...})`: the pre-send checks —
|
|
94
|
+
links, merge variables, subject, preview text, alt text, image weight, unsubscribe — each `pass`,
|
|
95
|
+
`warn` or `fail`. No link is visited.
|
|
96
|
+
- `rasket.broadcasts.send()` and `create()` take `acknowledge_checks`. Without it, a broadcast whose
|
|
97
|
+
content fails a check is refused with `422 validation_error`, and the error's `details` is a
|
|
98
|
+
`ChecksRefusal` listing the failing checks.
|
|
99
|
+
|
|
100
|
+
### Changed
|
|
101
|
+
|
|
102
|
+
- A Sending access key can no longer read contacts (and their imports and consent history),
|
|
103
|
+
segments, templates, saved blocks, broadcasts or automations: `contacts.*`, `segments.*`,
|
|
104
|
+
`templates.*`, `broadcasts.*` and `automations.*` reads now answer `401 restricted_api_key` for
|
|
105
|
+
one. Sending, events and topics are unchanged. Use a Full access key for those reads.
|
|
106
|
+
|
|
107
|
+
## 0.2.0 — 2026-10-01
|
|
108
|
+
|
|
109
|
+
### Added
|
|
110
|
+
|
|
111
|
+
- `rasket.team.brand_kit.upload({"content": ...})`: host a PNG, JPG or SVG (base64 `content`) and get
|
|
112
|
+
the URL it is served at. Send that URL as `brand_kit.logo_url` in `rasket.team.update()` to use it.
|
|
113
|
+
- `rasket.emails.metrics()` accepts `attempted`: each email that was sent, failed or suppressed, counted once.
|
|
114
|
+
- `RasketApiError.details` (`SandboxRefusal`): on the `403 validation_error` a send gets while its
|
|
115
|
+
region is still in our sending sandbox. It names the refused `recipient`, the `region`, and who
|
|
116
|
+
the sandbox delivers to.
|
|
117
|
+
- `rasket.team.get()` answers `sending.sandbox_regions`: the regions still in our sending sandbox.
|
|
118
|
+
- `rasket.team.get()` answers `sending.tier`, `sending.tier_name` and `sending.next_unlock`: the rung
|
|
119
|
+
of the sending ladder the team holds, and the one thing that lifts it.
|
|
120
|
+
- `rasket.emails.diagnose()` answers `cause`: `provider_failure` when the email failed on our mail servers'
|
|
121
|
+
side. The answer quotes the recorded reason and costs no AI credit. Null otherwise.
|
|
122
|
+
|
|
123
|
+
### Changed
|
|
124
|
+
|
|
125
|
+
- `rasket.emails.metrics()` refuses `unsubscribed` and `unsubscribe_rate` with `422 invalid_parameter`. They always
|
|
126
|
+
answered `0`; nothing counts an unsubscribe per email. `bounced_permanent`, `bounced_transient`,
|
|
127
|
+
`bounced_undetermined`, `unique_opened`, `unique_clicked` and `received` now answer real counts.
|
|
128
|
+
- `rasket.emails.send()` and `rasket.batch.send()`: `from` and `subject` are optional in `SendEmailRequest`. A send naming a published
|
|
129
|
+
`template` takes them from the template when the request leaves them out; with neither, the
|
|
130
|
+
send is still `422 missing_required_field`.
|
|
131
|
+
- The error name literal gains `invalid_api_key`: a `Bearer` credential that was sent but is not a
|
|
132
|
+
live key or OAuth access token. It used to arrive as `missing_api_key`, which is now only an
|
|
133
|
+
absent or malformed `Authorization` header. Both stay `401`.
|
|
134
|
+
|
|
135
|
+
## 0.1.0 — 2026-09-12
|
|
136
|
+
|
|
137
|
+
### Added
|
|
138
|
+
|
|
139
|
+
- `Rasket`, a synchronous client over `httpx`, with every method the Node client (`rasket` on npm,
|
|
140
|
+
0.4.0) has, under the same path with each segment in snake_case: `rasket.emails.send`,
|
|
141
|
+
`rasket.api_keys.create`, `rasket.emails.receiving.attachments.list`, `rasket.webhooks.verify`.
|
|
142
|
+
- Request, response and query types for every method, generated from the API's OpenAPI document,
|
|
143
|
+
in `rasket.types`.
|
|
144
|
+
- The Node client's request rules: its own `User-Agent`, `Idempotency-Key` passed through and
|
|
145
|
+
refused client-side outside 1–256 characters, retries only on a `GET` or a keyed send, the
|
|
146
|
+
rate-limit headers on every response, and `RasketApiError` carrying the API's error name.
|
|
147
|
+
- `rasket.webhooks.verify`, the signature check for a webhook delivery.
|
|
148
|
+
- `rasket.team`, `rasket.billing` and `rasket.ai`, the dashboard-parity methods, and
|
|
149
|
+
`rasket.contacts.imports.create`, which uploads the CSV as `multipart/form-data`.
|
|
150
|
+
- `rasket.webhooks.events.replay_many(webhook_id, event_ids)`, written by hand rather than
|
|
151
|
+
generated: it replays one event at a time and returns a `ReplayManyResult` whose `stopped` is the
|
|
152
|
+
refusal that ended the loop.
|
rasket-0.4.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Rasket
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
rasket-0.4.0/PKG-INFO
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: rasket
|
|
3
|
+
Version: 0.4.0
|
|
4
|
+
Summary: The Rasket Python client. Generated from the API's own OpenAPI document; retries only what is safe to repeat.
|
|
5
|
+
Project-URL: Repository, https://github.com/artsmedia-dev/rasket
|
|
6
|
+
Author: Rasket
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Keywords: api,client,email,rasket,sdk,transactional
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Topic :: Communications :: Email
|
|
19
|
+
Classifier: Typing :: Typed
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Requires-Dist: httpx<1,>=0.27
|
|
22
|
+
Requires-Dist: typing-extensions<5,>=4.13
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
|
|
25
|
+
# `rasket`
|
|
26
|
+
|
|
27
|
+
The Python client for the Rasket email API: transactional sends, templates, and the marketing side
|
|
28
|
+
(contacts, segments, topics, broadcasts). Typed from the API's own OpenAPI document, Python 3.10+,
|
|
29
|
+
built on `httpx`.
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
pip install rasket
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
import os
|
|
37
|
+
|
|
38
|
+
from rasket import Rasket
|
|
39
|
+
|
|
40
|
+
rasket = Rasket(api_key=os.environ["RASKET_API_KEY"], user_agent="acme-billing/1.0")
|
|
41
|
+
|
|
42
|
+
result = rasket.emails.send(
|
|
43
|
+
{
|
|
44
|
+
"from": "Acme <billing@acme.example>",
|
|
45
|
+
"to": ["ronald.williams@example.com"],
|
|
46
|
+
"subject": "Your receipt",
|
|
47
|
+
"html": "<p>Thanks.</p>",
|
|
48
|
+
},
|
|
49
|
+
idempotency_key="receipt-1042",
|
|
50
|
+
)
|
|
51
|
+
print(result.body["id"])
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## What every call returns
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
result = rasket.emails.get(email_id)
|
|
58
|
+
|
|
59
|
+
result.body # the parsed JSON body, typed per route (rasket.types)
|
|
60
|
+
result.rate_limit # RateLimit(limit=10, remaining=9, reset_seconds=1, retry_after_seconds=None)
|
|
61
|
+
result.request_id # the x-request-id to quote when asking about a request
|
|
62
|
+
result.idempotent_replayed # True when this is the original response to an earlier keyed request
|
|
63
|
+
result.etag # the ETag when the API sent one (inbox.conversations.get and update), else None
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
For a list route, `body` is the list envelope: `{"object": "list", "has_more": ..., "data": [...]}`.
|
|
67
|
+
`contacts.list` is the one list whose envelope has no `has_more`, as the reference API's has none:
|
|
68
|
+
page it with `after` until `data` comes back empty.
|
|
69
|
+
|
|
70
|
+
## The surface
|
|
71
|
+
|
|
72
|
+
Every method of the Node client exists here under the same path, each segment in snake_case:
|
|
73
|
+
`rasket.api_keys.create`, `rasket.webhooks.rotate_secret`, `rasket.automations.list_runs`. Path
|
|
74
|
+
parameters come first, positionally; then `body` or `query` as a dict; `idempotency_key` is a
|
|
75
|
+
keyword on the routes that take one (`emails.send`, `batch.send`, `sms.send`, `sms.batch`, the two
|
|
76
|
+
`send_test`s, and the Inbox's `conversations.create`, `conversations.reply` and
|
|
77
|
+
`conversations.notes.create`). `if_match`
|
|
78
|
+
is a keyword on `inbox.conversations.update`: pass an earlier `etag` to refuse a change made since
|
|
79
|
+
(`412 precondition_failed`). Both clients are generated from the same route map, so neither can
|
|
80
|
+
gain a method the other lacks.
|
|
81
|
+
|
|
82
|
+
`rasket.inbox` reaches your team's shared Inbox channels, never anyone's personal mailbox. An API
|
|
83
|
+
key needs Inbox access, which an admin turns on under API keys.
|
|
84
|
+
|
|
85
|
+
`rasket.sms` texts US and Canadian phones. The field is `text`, never `body`, because `body` is
|
|
86
|
+
already the response:
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
response = rasket.sms.send(
|
|
90
|
+
{"to": "+14155550123", "text": "Acme: your order #1042 has shipped."},
|
|
91
|
+
idempotency_key="order-1042-shipped",
|
|
92
|
+
)
|
|
93
|
+
response.body["segments"] # messages it is billed as: 160 characters each, 70 with an emoji
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
A marketing text needs the contact's SMS consent, set with `contacts.sms_consent.update` and proof
|
|
97
|
+
of where they agreed; a topic subscription is not consent. `429 sms_quota_exceeded` is never
|
|
98
|
+
retried.
|
|
99
|
+
|
|
100
|
+
`rasket.autopilot` reads Autopilot's settings and approves or skips the campaigns it proposes:
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
proposals = rasket.autopilot.proposals.list({"status": "proposed"}).body["data"]
|
|
104
|
+
if proposals:
|
|
105
|
+
rasket.autopilot.proposals.approve(proposals[0]["id"], {"send_at": "tomorrow at 9am"})
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
`approve` runs the same pre-send checks as `broadcasts.send` (a failing check is `422`, with the
|
|
109
|
+
checks in `details.checks`) and needs `broadcasts:write` as well as `autopilot:write`.
|
|
110
|
+
`rasket.autopilot.playbook.get()` returns what Autopilot learned from your results and edits; an
|
|
111
|
+
admin can `use`, `dismiss` or `restore` a version, or `reset` to the defaults.
|
|
112
|
+
`rasket.autopilot.kinds.list()` says whether each kind of campaign has earned sending on its own;
|
|
113
|
+
with `approval_mode="earned"`, an admin puts a `ready` one on Auto with
|
|
114
|
+
`rasket.autopilot.kinds.update("price_drop", {"auto": True})`, and
|
|
115
|
+
`rasket.autopilot.proposals.cancel(id)` stops a scheduled one until 30 minutes before it sends.
|
|
116
|
+
|
|
117
|
+
## Errors
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
from rasket import RasketApiError, RasketConnectionError
|
|
121
|
+
|
|
122
|
+
try:
|
|
123
|
+
rasket.emails.send(message)
|
|
124
|
+
except RasketApiError as error:
|
|
125
|
+
if error.name == "validation_error":
|
|
126
|
+
print(error.errors) # (ValidationIssue(path=..., message=...), ...)
|
|
127
|
+
elif error.name == "rate_limit_exceeded" and error.rate_limit is not None:
|
|
128
|
+
print(error.rate_limit.retry_after_seconds)
|
|
129
|
+
else:
|
|
130
|
+
raise
|
|
131
|
+
except RasketConnectionError as error:
|
|
132
|
+
print(error.reason) # "network" or "timeout": no answer arrived
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
`error.name` is the API's error vocabulary, not a class name. `unknown_error` means the response did
|
|
136
|
+
not carry a Rasket error body. An `Idempotency-Key` outside 1–256 characters is refused before any
|
|
137
|
+
request is sent, as the same `400 invalid_idempotency_key`, with `error.source == "client"`.
|
|
138
|
+
|
|
139
|
+
## Retries
|
|
140
|
+
|
|
141
|
+
A `GET` is retried, and so is a send carrying an `idempotency_key`; nothing else is. A retry happens
|
|
142
|
+
on a network failure, `429 rate_limit_exceeded` (never a quota 429), a `5xx` other than `501`, and
|
|
143
|
+
`409 concurrent_idempotent_requests`. `retry-after` is honoured, and a value above `max_delay` is not
|
|
144
|
+
waited for — the error is raised at once. Otherwise the wait is exponential with full jitter.
|
|
145
|
+
|
|
146
|
+
```python
|
|
147
|
+
from rasket import Rasket, RetryOptions
|
|
148
|
+
|
|
149
|
+
rasket = Rasket(
|
|
150
|
+
api_key=api_key, timeout=30.0, retry=RetryOptions(attempts=3, min_delay=0.5, max_delay=8.0)
|
|
151
|
+
)
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Verifying a webhook
|
|
155
|
+
|
|
156
|
+
```python
|
|
157
|
+
from rasket import WebhookVerificationError, webhooks
|
|
158
|
+
|
|
159
|
+
try:
|
|
160
|
+
event = webhooks.verify(raw_body, headers, os.environ["RASKET_WEBHOOK_SECRET"])
|
|
161
|
+
except WebhookVerificationError as error:
|
|
162
|
+
print(error.reason)
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Pass the body exactly as it arrived (`request.get_data()` in Flask, `await request.body()` in
|
|
166
|
+
FastAPI) — the signature covers the bytes, not a re-serialized object. `rasket.webhooks.verify` on a
|
|
167
|
+
client is the same function.
|
|
168
|
+
|
|
169
|
+
## Worth knowing
|
|
170
|
+
|
|
171
|
+
- The client is synchronous in 0.1.0. Close it with `rasket.close()` or use it as a context manager.
|
|
172
|
+
- An OAuth access token works everywhere `api_key` does.
|
rasket-0.4.0/README.md
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# `rasket`
|
|
2
|
+
|
|
3
|
+
The Python client for the Rasket email API: transactional sends, templates, and the marketing side
|
|
4
|
+
(contacts, segments, topics, broadcasts). Typed from the API's own OpenAPI document, Python 3.10+,
|
|
5
|
+
built on `httpx`.
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pip install rasket
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```python
|
|
12
|
+
import os
|
|
13
|
+
|
|
14
|
+
from rasket import Rasket
|
|
15
|
+
|
|
16
|
+
rasket = Rasket(api_key=os.environ["RASKET_API_KEY"], user_agent="acme-billing/1.0")
|
|
17
|
+
|
|
18
|
+
result = rasket.emails.send(
|
|
19
|
+
{
|
|
20
|
+
"from": "Acme <billing@acme.example>",
|
|
21
|
+
"to": ["ronald.williams@example.com"],
|
|
22
|
+
"subject": "Your receipt",
|
|
23
|
+
"html": "<p>Thanks.</p>",
|
|
24
|
+
},
|
|
25
|
+
idempotency_key="receipt-1042",
|
|
26
|
+
)
|
|
27
|
+
print(result.body["id"])
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## What every call returns
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
result = rasket.emails.get(email_id)
|
|
34
|
+
|
|
35
|
+
result.body # the parsed JSON body, typed per route (rasket.types)
|
|
36
|
+
result.rate_limit # RateLimit(limit=10, remaining=9, reset_seconds=1, retry_after_seconds=None)
|
|
37
|
+
result.request_id # the x-request-id to quote when asking about a request
|
|
38
|
+
result.idempotent_replayed # True when this is the original response to an earlier keyed request
|
|
39
|
+
result.etag # the ETag when the API sent one (inbox.conversations.get and update), else None
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
For a list route, `body` is the list envelope: `{"object": "list", "has_more": ..., "data": [...]}`.
|
|
43
|
+
`contacts.list` is the one list whose envelope has no `has_more`, as the reference API's has none:
|
|
44
|
+
page it with `after` until `data` comes back empty.
|
|
45
|
+
|
|
46
|
+
## The surface
|
|
47
|
+
|
|
48
|
+
Every method of the Node client exists here under the same path, each segment in snake_case:
|
|
49
|
+
`rasket.api_keys.create`, `rasket.webhooks.rotate_secret`, `rasket.automations.list_runs`. Path
|
|
50
|
+
parameters come first, positionally; then `body` or `query` as a dict; `idempotency_key` is a
|
|
51
|
+
keyword on the routes that take one (`emails.send`, `batch.send`, `sms.send`, `sms.batch`, the two
|
|
52
|
+
`send_test`s, and the Inbox's `conversations.create`, `conversations.reply` and
|
|
53
|
+
`conversations.notes.create`). `if_match`
|
|
54
|
+
is a keyword on `inbox.conversations.update`: pass an earlier `etag` to refuse a change made since
|
|
55
|
+
(`412 precondition_failed`). Both clients are generated from the same route map, so neither can
|
|
56
|
+
gain a method the other lacks.
|
|
57
|
+
|
|
58
|
+
`rasket.inbox` reaches your team's shared Inbox channels, never anyone's personal mailbox. An API
|
|
59
|
+
key needs Inbox access, which an admin turns on under API keys.
|
|
60
|
+
|
|
61
|
+
`rasket.sms` texts US and Canadian phones. The field is `text`, never `body`, because `body` is
|
|
62
|
+
already the response:
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
response = rasket.sms.send(
|
|
66
|
+
{"to": "+14155550123", "text": "Acme: your order #1042 has shipped."},
|
|
67
|
+
idempotency_key="order-1042-shipped",
|
|
68
|
+
)
|
|
69
|
+
response.body["segments"] # messages it is billed as: 160 characters each, 70 with an emoji
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
A marketing text needs the contact's SMS consent, set with `contacts.sms_consent.update` and proof
|
|
73
|
+
of where they agreed; a topic subscription is not consent. `429 sms_quota_exceeded` is never
|
|
74
|
+
retried.
|
|
75
|
+
|
|
76
|
+
`rasket.autopilot` reads Autopilot's settings and approves or skips the campaigns it proposes:
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
proposals = rasket.autopilot.proposals.list({"status": "proposed"}).body["data"]
|
|
80
|
+
if proposals:
|
|
81
|
+
rasket.autopilot.proposals.approve(proposals[0]["id"], {"send_at": "tomorrow at 9am"})
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
`approve` runs the same pre-send checks as `broadcasts.send` (a failing check is `422`, with the
|
|
85
|
+
checks in `details.checks`) and needs `broadcasts:write` as well as `autopilot:write`.
|
|
86
|
+
`rasket.autopilot.playbook.get()` returns what Autopilot learned from your results and edits; an
|
|
87
|
+
admin can `use`, `dismiss` or `restore` a version, or `reset` to the defaults.
|
|
88
|
+
`rasket.autopilot.kinds.list()` says whether each kind of campaign has earned sending on its own;
|
|
89
|
+
with `approval_mode="earned"`, an admin puts a `ready` one on Auto with
|
|
90
|
+
`rasket.autopilot.kinds.update("price_drop", {"auto": True})`, and
|
|
91
|
+
`rasket.autopilot.proposals.cancel(id)` stops a scheduled one until 30 minutes before it sends.
|
|
92
|
+
|
|
93
|
+
## Errors
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
from rasket import RasketApiError, RasketConnectionError
|
|
97
|
+
|
|
98
|
+
try:
|
|
99
|
+
rasket.emails.send(message)
|
|
100
|
+
except RasketApiError as error:
|
|
101
|
+
if error.name == "validation_error":
|
|
102
|
+
print(error.errors) # (ValidationIssue(path=..., message=...), ...)
|
|
103
|
+
elif error.name == "rate_limit_exceeded" and error.rate_limit is not None:
|
|
104
|
+
print(error.rate_limit.retry_after_seconds)
|
|
105
|
+
else:
|
|
106
|
+
raise
|
|
107
|
+
except RasketConnectionError as error:
|
|
108
|
+
print(error.reason) # "network" or "timeout": no answer arrived
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
`error.name` is the API's error vocabulary, not a class name. `unknown_error` means the response did
|
|
112
|
+
not carry a Rasket error body. An `Idempotency-Key` outside 1–256 characters is refused before any
|
|
113
|
+
request is sent, as the same `400 invalid_idempotency_key`, with `error.source == "client"`.
|
|
114
|
+
|
|
115
|
+
## Retries
|
|
116
|
+
|
|
117
|
+
A `GET` is retried, and so is a send carrying an `idempotency_key`; nothing else is. A retry happens
|
|
118
|
+
on a network failure, `429 rate_limit_exceeded` (never a quota 429), a `5xx` other than `501`, and
|
|
119
|
+
`409 concurrent_idempotent_requests`. `retry-after` is honoured, and a value above `max_delay` is not
|
|
120
|
+
waited for — the error is raised at once. Otherwise the wait is exponential with full jitter.
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
from rasket import Rasket, RetryOptions
|
|
124
|
+
|
|
125
|
+
rasket = Rasket(
|
|
126
|
+
api_key=api_key, timeout=30.0, retry=RetryOptions(attempts=3, min_delay=0.5, max_delay=8.0)
|
|
127
|
+
)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Verifying a webhook
|
|
131
|
+
|
|
132
|
+
```python
|
|
133
|
+
from rasket import WebhookVerificationError, webhooks
|
|
134
|
+
|
|
135
|
+
try:
|
|
136
|
+
event = webhooks.verify(raw_body, headers, os.environ["RASKET_WEBHOOK_SECRET"])
|
|
137
|
+
except WebhookVerificationError as error:
|
|
138
|
+
print(error.reason)
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Pass the body exactly as it arrived (`request.get_data()` in Flask, `await request.body()` in
|
|
142
|
+
FastAPI) — the signature covers the bytes, not a re-serialized object. `rasket.webhooks.verify` on a
|
|
143
|
+
client is the same function.
|
|
144
|
+
|
|
145
|
+
## Worth knowing
|
|
146
|
+
|
|
147
|
+
- The client is synchronous in 0.1.0. Close it with `rasket.close()` or use it as a context manager.
|
|
148
|
+
- An OAuth access token works everywhere `api_key` does.
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# The Python client (A117). Not a pnpm workspace: `pnpm-workspace.yaml` excludes this directory,
|
|
2
|
+
# so Turbo, ESLint and `graph.js` never see it. Its toolchain is uv, ruff, mypy and pytest, each
|
|
3
|
+
# pinned exactly below and resolved once in `uv.lock` for every Python this package supports.
|
|
4
|
+
[project]
|
|
5
|
+
name = "rasket"
|
|
6
|
+
version = "0.4.0"
|
|
7
|
+
description = "The Rasket Python client. Generated from the API's own OpenAPI document; retries only what is safe to repeat."
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
license = "MIT"
|
|
10
|
+
license-files = ["LICENSE"]
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
authors = [{ name = "Rasket" }]
|
|
13
|
+
keywords = ["rasket", "email", "transactional", "api", "client", "sdk"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 4 - Beta",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
19
|
+
"Programming Language :: Python :: 3.10",
|
|
20
|
+
"Programming Language :: Python :: 3.11",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Programming Language :: Python :: 3.13",
|
|
23
|
+
"Topic :: Communications :: Email",
|
|
24
|
+
"Typing :: Typed",
|
|
25
|
+
]
|
|
26
|
+
# httpx is the transport. typing_extensions carries `NotRequired` for the generated TypedDicts on
|
|
27
|
+
# 3.10, where `typing` does not have it yet.
|
|
28
|
+
dependencies = ["httpx>=0.27,<1", "typing_extensions>=4.13,<5"]
|
|
29
|
+
|
|
30
|
+
[project.urls]
|
|
31
|
+
Repository = "https://github.com/artsmedia-dev/rasket"
|
|
32
|
+
|
|
33
|
+
[dependency-groups]
|
|
34
|
+
dev = [
|
|
35
|
+
"datamodel-code-generator==0.79.0",
|
|
36
|
+
"httpx==0.28.1",
|
|
37
|
+
"mypy==2.3.1",
|
|
38
|
+
"pytest==9.1.1",
|
|
39
|
+
"respx==0.23.1",
|
|
40
|
+
"ruff==0.16.7",
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
[build-system]
|
|
44
|
+
requires = ["hatchling==1.32.0"]
|
|
45
|
+
build-backend = "hatchling.build"
|
|
46
|
+
|
|
47
|
+
[tool.hatch.build.targets.wheel]
|
|
48
|
+
packages = ["src/rasket"]
|
|
49
|
+
|
|
50
|
+
# The sdist is the source a customer could rebuild the wheel from, and nothing else: no tests (they
|
|
51
|
+
# read the monorepo's OpenAPI document by path), no generator, no lockfile.
|
|
52
|
+
[tool.hatch.build.targets.sdist]
|
|
53
|
+
include = ["src/rasket", "README.md", "CHANGELOG.md", "LICENSE", "pyproject.toml"]
|
|
54
|
+
|
|
55
|
+
[tool.uv]
|
|
56
|
+
required-version = "==0.12.13"
|
|
57
|
+
|
|
58
|
+
[tool.ruff]
|
|
59
|
+
line-length = 100
|
|
60
|
+
target-version = "py310"
|
|
61
|
+
|
|
62
|
+
[tool.ruff.lint]
|
|
63
|
+
select = ["E", "F", "W", "I", "B", "UP", "A", "N", "RUF", "SIM", "PT", "ANN"]
|
|
64
|
+
# `_types.py` is generated; its field names are the API's wire names (`statusCode`, `from`).
|
|
65
|
+
[tool.ruff.lint.per-file-ignores]
|
|
66
|
+
"src/rasket/_types.py" = ["N815", "UP", "RUF", "E501", "A", "ANN"]
|
|
67
|
+
# Docstrings carry the operation summary from the document, which has no line limit.
|
|
68
|
+
"src/rasket/resources/**" = ["E501"]
|
|
69
|
+
"tests/**" = ["ANN"]
|
|
70
|
+
|
|
71
|
+
[tool.mypy]
|
|
72
|
+
strict = true
|
|
73
|
+
python_version = "3.10"
|
|
74
|
+
files = ["src"]
|
|
75
|
+
|
|
76
|
+
[tool.pytest.ini_options]
|
|
77
|
+
testpaths = ["tests"]
|
|
78
|
+
addopts = ["--strict-markers"]
|