unitpost 0.4.0__tar.gz → 0.5.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.
@@ -0,0 +1,324 @@
1
+ # Changelog
2
+
3
+ Notable changes to the Unitpost Python SDK. Changes to the API itself (new
4
+ operations, new fields, behavior changes) are in the API changelog:
5
+ https://www.unitpost.com/docs/changelog.
6
+
7
+ To release, move the `Unreleased` items under a `## X.Y.Z` heading in the same
8
+ change that bumps the version (docs/sdk/RELEASING.md).
9
+
10
+ ## Unreleased
11
+
12
+ ## 0.5.0
13
+
14
+ - `UnitpostOrganization` gains `shared_plan`: `get`, `list_workspaces`, `add_workspace`, `update_workspace`, `remove_workspace` (the organization's shared plan; adding and removing take an optional `idempotency_key`, or the SDK mints one). Reads need `organizations:read`; the three writes need `organizations:billing`. Buying, upgrading or ending the shared plan stays in the dashboard.
15
+ - SMS tags: `sms.send({..., "tags": [{"name": ..., "value": ...}]})` (up to 10) and the `tag` filter on `sms.list(tag=...)` / `sms.list_all(tag=...)` (`tag` is `name:value`; several comma-separated must all match; received texts have none). The SMS object carries `tags` (`SmsTagsItem`).
16
+ - `UnitpostOrganization` iterators: `webhooks.list_all()`, `webhooks.list_all_deliveries(webhook_id)` and `usage.list_all()` (pages by `workspace_id`). The delivery log needs `organizations:write`.
17
+ - `spend_caps` (new, ADR-0172): the workspace's monthly spend caps. `get()` reads the SMS-purchase cap, its `max_cents` and what it counted this UTC month; `update(body)` sets or clears it and needs `spend_caps:write`, which no key preset includes. A workspace its organization pays for answers `403 billed_by_organization`.
18
+ - `UnitpostOrganization` (new, ADR-0171): the client for an organization key
19
+ (`ok_live_...`), made with the key and the organization's id
20
+ (`UNITPOST_ORG_KEY` and `UNITPOST_ORGANIZATION_ID` when left out). It has
21
+ `workspaces` (`list`, `list_all`, `create` with an idempotency key, `get`,
22
+ `update`, `close`, `restore`), `workspace_keys.create`, `webhooks` (the
23
+ organization's endpoints), `usage.list` and `plan_quotes` (`create`, `get`,
24
+ `confirm` with an idempotency key). The workspace client `Unitpost` doesn't
25
+ carry them.
26
+ - `sms.add_contact(id)`, `sms.list_join_keywords(number_id)`, `sms.add_join_keyword(number_id, body)`, `sms.remove_join_keyword(number_id, keyword_id)`: add a texter as a contact and manage text-to-join keywords.
27
+ - `SmsFailureCode` gains `sms_not_in_plan`: SMS wasn't on the plan when a text was due (the paid plan ended after its grace, or the plan is 100% discounted). Not charged.
28
+ - SMS numbers and registrations, start to finish (ADR-0160, 2026-11-12):
29
+ `sms.get_number(id)`, `sms.release_number(id, {"force": True},
30
+ idempotency_key=...)` (permanent), `sms.registrations.get(id)`,
31
+ `sms.registrations.remove(id)` (a 10DLC setup with no number) and
32
+ `sms.registrations.replace(id)` (an approved brand registration).
33
+ - Files and SMS onboarding by API (ADR-0159, 2026-11-12):
34
+ - `files` (new): `list(purpose=...)`, `create(body, idempotency_key=...)`,
35
+ `get(id)`, `delete(id)`. A file (`file_` id) is bytes handed to the API
36
+ for one `purpose` (`sms_opt_in_evidence`, `sms_document`, `image`) from a
37
+ `url`, base64 `data`, or an upload session, used by `file_id` and
38
+ expiring after 24 hours.
39
+ - `files.upload(path_or_bytes, purpose=..., content_type=...,
40
+ filename=None, idempotency_key=None)`: sends a file up to 3 MB inline,
41
+ and a larger one through an upload session (the create, a PUT of the
42
+ bytes with exactly `upload["headers"]`, then `get`).
43
+ - `sms`: a brand's documents (`list_brand_documents(brand_id)`,
44
+ `add_brand_document(brand_id, body, idempotency_key=...)`,
45
+ `get_brand_document`, `remove_brand_document`, and
46
+ `brand_document_url`, a 5-minute signed link), and
47
+ `resubmit_number(number_id, body, idempotency_key=...)` for a toll-free
48
+ verification carriers sent back.
49
+ - `sms.registrations`: `resubmit(id, body, idempotency_key=...)` for a
50
+ 10DLC campaign carriers sent back, and `request_number(id,
51
+ idempotency_key=...)` to retry a failed number whose fee is committed.
52
+ - Every new write generates an Idempotency-Key when you don't pass one.
53
+ - `error.doc_url`: the page the API links for an error, when it links one (today `sending_paused`, a paused sending stream; ADR-0156). `null`/`None` otherwise. The `Campaign.pause_reason.code` union adds `sending_paused`.
54
+ - `UnitpostError.details` entries document the optional `code`, a
55
+ machine-readable reason for the entry, such as the SMS skip word on `to`
56
+ (`out_of_reach`).
57
+ - The SMS list takes `sender_id`, a number's `snum_…` id: that number's
58
+ texts, both directions. A value it can't apply is ignored and named in the
59
+ `Unitpost-Warning` response header; `Unitpost-Strict: true` refuses it.
60
+ - `sms.quotes` (new): `create(body)`, `get(id)` and `confirm(id,
61
+ {"confirm_token": ...}, idempotency_key=...)` buy SMS carrier resources
62
+ (`squote_` ids): register a 10DLC brand, vet it, register a campaign, order
63
+ a number. `confirm` generates an Idempotency-Key when you don't pass one, so
64
+ a retry can't buy twice. `create` prices the order and binds what it buys
65
+ (the brand's and program's content, the price) and returns `due_now_cents`,
66
+ `monthly_cents`, `line_items` and a single-use `confirm_token` (`sqct_`),
67
+ only in that response; a quote lasts 10 minutes and charges nothing. The
68
+ confirm places the order at that price, or answers `409` when the price or
69
+ content changed. It needs `sms:purchase`, which no key preset includes, and
70
+ the workspace owner's monthly cap for SMS purchases by API (no cap set
71
+ refuses it). Show the person the price and get their yes before confirming.
72
+ - `logs.list()` (new `logs` resource): the workspace's API request log,
73
+ newest first and cursor-paginated (`rlog_` ids). Each row is one call:
74
+ `method`, `path`, `status`, `duration_ms`, `api_key_id` and its
75
+ `request_id` (the `x-request-id`), never the caller's IP or a body; rows are
76
+ kept 30 days. Filters: `status` (a code or `2xx`…`5xx`), `api_key_id`,
77
+ `method`, `path_prefix`, `request_id`, `created_after`, `created_before`. It
78
+ needs `apikeys:read`, which no key preset includes.
79
+ - Opt many contacts out of a topic at once: `email.topics.opt_out(id, body,
80
+ idempotency_key=None)` and `sms.topics.opt_out(...)` (exactly one of
81
+ `contact_ids` or `emails`, up to 1,000, or `segment_id`). They answer the
82
+ job (202); follow it with `jobs.get(id)`. The SDK mints an idempotency key
83
+ when you pass none, so a retry answers the same job. There is no bulk
84
+ opt-in. Needs `topics:write` (a segment also `segments:read`).
85
+ - `sms.registrations.list()`, `sms.test_destinations.list()`,
86
+ `sms.consent_setups.list()`, `sms.billing.list_resources()` and
87
+ `sms.messaging_programs.list()` take `limit`, `after` and `before`: the
88
+ five lists are cursor-paginated, newest first.
89
+ - New response fields are `NotRequired` in the models (the API always sends
90
+ them), so a dict typed as a model with only its 0.4.0 keys still
91
+ type-checks.
92
+ - The activity log, an API key's usage, several topic preferences at once and
93
+ list search. `workspace.list_activity()` and `list_all_activity()`: the
94
+ workspace's activity log, newest first (cursor-paginated on `act_` ids):
95
+ what changed, when, who (`actor.name`) and, for a change over the API, MCP
96
+ or Ask Unit, how (`actor.via`, with the API key). Narrow it with `subject=`
97
+ (and `subject_id=`), `contact_id=`, `campaign_id=`, `q=` and
98
+ `channel="email"` (an unknown keyword is a `422`). It needs `activity:read`.
99
+ `api_keys.usage(id)`: a key's requests in the last 24 hours (`requests_24h`,
100
+ `client_errors_24h`, `server_errors_24h`, `rate_limited_24h`) and
101
+ `last_used_at`. `api_keys.list` now also works with an API key or an MCP
102
+ sign-in (it was dashboard-session only); with one, `list` and `usage` need
103
+ `apikeys:read`. Creating and revoking keys stay in the dashboard. No key
104
+ preset includes `activity:read` or `apikeys:read`.
105
+ `email.topics.update_topics(contact_id, {"topics": [{"topic_id": ...,
106
+ "subscribed": ...}]})` (`PATCH /contacts/{id}/topics`, up to 50) changes
107
+ several of a contact's preferences at once, leaves the others as they are,
108
+ and answers the list (`{"object": "list", "has_more": False, "data":
109
+ [...]}`); `set_topic` is unchanged. `email.list` and `list_all` take `q=` (an exact
110
+ recipient, or part of the subject or the sender), `source=` (`"api"`,
111
+ `"smtp"`, `"test"`, `"batch"`, `"campaign"` or `"reply"`) and `outcome=`
112
+ (`"delivered"`, `"opened"`, `"clicked"`, `"unsubscribed"`, `"bounced"`,
113
+ `"complained"`, `"failed"` or `"pending"`; with `campaign_id=`, who opened
114
+ or clicked it). `sms.list` and `list_all` take `q=` (the message text, or 3
115
+ or more digits of either number) and `type=` (`"transactional"` or
116
+ `"marketing"`). A `q`, `source`, `outcome` or `type` value the API can't
117
+ apply is ignored and named in the `Unitpost-Warning` response header;
118
+ `Unitpost-Strict: true` refuses it.
119
+ - List filters and a stats period. `suppressions.list` and `list_all` take
120
+ `q=` (part of the address), `reason=`, `created_after=` and
121
+ `created_before=` (`scope` stays, deprecated). `webhooks.list_deliveries`
122
+ and `list_all_deliveries` take `status=` (comma-separated, e.g.
123
+ `"failed,exhausted"`) and `event_type=`. `email.stats` keeps `days=` and
124
+ takes a period instead: `from_=` (sent as `from`) and `to=`, with `grain=`
125
+ (`"5m"`, `"1h"` or `"1d"`) and `tz=` for `series`, the send volume per
126
+ bucket, and `domain_id=` for one sending domain. These lists ignored the
127
+ filters before, so a value the API can't apply is ignored and named in the
128
+ `Unitpost-Warning` response header; `Unitpost-Strict: true` refuses it.
129
+ Responses: `webhooks.get` adds `backlog` (`queued`, `failed`: what a flush
130
+ would send); `email.stats` adds the permanent and transient bounces,
131
+ `suppressed`, `unsubscribed`, `rates.unsubscribe`, `domain_id`, `from`, `to`
132
+ and `series`; topics add `subscriber_count` and `unsubscribed_count`;
133
+ `usage.get` adds the plan's `limits` and `features`.
134
+ - Who is calling, an email's events, a received email's original and
135
+ template rendering. `workspace.whoami()`: the workspace, the credential (an
136
+ API key or an OAuth sign-in, never its secret), its `capabilities` and the
137
+ workspace's rate limit; any valid credential may call it, so call it first
138
+ to see what a key may do.
139
+ `email.list_events(id, limit=..., after=..., before=...)`: one email's
140
+ delivery events, oldest first, with each event's detail under the webhook's
141
+ names (cursor-paginated on `emev_` ids; no `list_all`).
142
+ `email.received_raw(id)`: a signed URL (about 5 minutes) to a received
143
+ message's original `.eml`, the way to read a body over 256 KB; a copy of
144
+ your own send is a `403`.
145
+ `email.templates.render(id, {"variables": ..., "subject": ..., "contact_id": ...})`:
146
+ the subject, HTML and text a send would carry, and its
147
+ `missing_variables`; it sends and stores nothing, so it takes no
148
+ idempotency key, and the body is optional. `list_events` and
149
+ `received_raw` need `emails:read`; `render` needs `templates:read`.
150
+ - SMS brands and registrations. On `sms`:
151
+ `create_brand(body, idempotency_key=...)`, `get_brand(id)` and
152
+ `update_brand(id, {...})` (send `{"archived": ...}` alone to archive or
153
+ restore). A new resource on `sms`: `sms.registrations.list()`, which is
154
+ cursor-paginated (no `list_all`). Creating a brand is free and makes no
155
+ carrier call; its tax id is write-only (read back as
156
+ `tax_id_on_file`), and a locked brand refuses carrier-field edits with
157
+ `409 brand_locked`. The reads need `sms:read`; the brand writes need
158
+ `sms:manage`. Registering a brand with carriers (a paid step), ordering
159
+ numbers and a brand's documents stay in the dashboard.
160
+ - SMS setup. On `sms.templates`: `usage(id)` and
161
+ `test_send(id, {"to": ..., "variables": ..., "sender_id": ...}, idempotency_key=...)`.
162
+ Four new resources on `sms`: `sms.messaging_programs.list(archived=...)`,
163
+ `create(body, idempotency_key=...)`, `get(id)`, `update(id, {...})`,
164
+ `delete(id)` (it archives) and `duplicate(id, idempotency_key=...)`;
165
+ `sms.test_destinations.list()` and `delete(id)`;
166
+ `sms.consent_setups.list()`; and `sms.billing.list_resources()`. These four
167
+ lists are cursor-paginated (no `list_all`). A test text goes only to the
168
+ simulator or a verified test number, and is billed like any
169
+ text. The reads need `sms:read` (`usage` needs `templates:read`); the test
170
+ send needs `sms:send`; the program writes and removing a test number need
171
+ `sms:manage` (FULL keys have it, SENDING keys don't). Ordering numbers,
172
+ sender registrations and payments stay in the dashboard.
173
+ - Brand Kit writes and imports on `brand_kits`:
174
+ `brand_kits.create({"name": ..., "make_default": ...})`,
175
+ `brand_kits.update(id, {...})`, `brand_kits.delete(id)`,
176
+ `brand_kits.reset(id)`, `brand_kits.set_default(id)` and
177
+ `brand_kits.add_graphic(id, {"url": ..., "role": ..., "label": ...})`;
178
+ `brand_kits.import_({...})` (`import` is a Python keyword),
179
+ `brand_kits.get_import(id)`, `brand_kits.accept_import(id, {...})` (the body
180
+ is optional) and `brand_kits.cancel_import(id)`. An import builds a profile
181
+ from a website (`url`) or the brand's own words (`text`) in the background
182
+ (`202`; follow it with `get_import`). By default it is applied when it
183
+ lands; with `"review": True` it stops at a proposal for `accept_import`.
184
+ Deleting the last profile is a `409` (reset it instead). `add_graphic`
185
+ brings an image from a public https URL into the image library and pins it.
186
+ The writes, and starting, accepting or canceling an import, need the
187
+ `branding:write` capability, which no key preset grants: tick it on the key.
188
+ The reads stay `templates:read`.
189
+ - Three new resources. Image library:
190
+ `library_images.list(limit=..., after=..., before=...)`,
191
+ `library_images.list_all()`,
192
+ `library_images.create({...}, idempotency_key=...)`,
193
+ `library_images.get(id)`, `library_images.update(id, {"alt": ...})` and
194
+ `library_images.delete(id, force=True)`. Branding: `branding.get()`,
195
+ `branding.update({...})`, `branding.set_logo({...})` and
196
+ `branding.remove_logo()`. Workspace:
197
+ `workspace.update({"name": ...})`, `workspace.set_image({...})` and
198
+ `workspace.remove_image()`. The library holds the images a template
199
+ embeds: an image's `path` (`/img/…`) goes in a template's `<Image src>`.
200
+ `create` uploads from a public https `url` or base64 `data` (PNG, JPEG,
201
+ GIF or WebP, up to 5 MB) and takes an `idempotency_key`, minted when you
202
+ don't pass one, so a retried upload stores one image. Deleting an image
203
+ that a template, a campaign or sent mail uses is a `409` `resource_in_use`
204
+ unless you pass `force=True` (sent as `?force=true`). `branding` is the
205
+ look of marketing emails' footer and the hosted unsubscribe page, as
206
+ Settings → Brand shows it (`None` restores a default). `workspace` renames
207
+ the workspace and sets its image. `remove_logo` and `remove_image` answer
208
+ the updated object. The branding writes and every `workspace` call need
209
+ the `branding:write` capability, which no key preset grants: tick it on
210
+ the key.
211
+ - Jobs: `jobs.list(status=..., kind=..., limit=..., after=..., before=...)`,
212
+ `jobs.cancel(id)`, `jobs.retry(id)` and `jobs.download(id)`. Contacts:
213
+ `contacts.export({"q": ..., "status": ..., "segment_id": ...})` (the
214
+ filters of `contacts.list`). Segments: `segments.preview(id)`,
215
+ `segments.preview_filter({"filter": ...})`, `segments.all_contacts()` and
216
+ `segments.update_member(id, contact, {"subscribed": ...})`.
217
+ `export` starts a background job that writes a CSV of every contact, or
218
+ of the ones the filters match (one export at a time: another while it runs
219
+ is a `409`); follow it with `jobs.get`, then `jobs.download` gives a signed URL to
220
+ the file that expires in 5 minutes. `jobs.list` lists your background jobs;
221
+ `cancel` stops a queued or running one, and `retry` resumes a `FAILED`
222
+ one from where it stopped. `preview` and `preview_filter`
223
+ count who a saved segment or an unsaved filter reaches and how many of them
224
+ a campaign would mail; nothing is saved. `all_contacts` returns the
225
+ managed "All subscribed contacts" segment, made the first time you ask.
226
+ `update_member` opts a member out of a static segment's sends, or back
227
+ in, without removing it. None of these takes an idempotency key.
228
+ - Webhooks: `webhooks.replay_delivery(id, delivery_id)` and
229
+ `webhooks.flush(id, {"include_failed": ...})`. Email:
230
+ `email.retry(id, idempotency_key=...)` and
231
+ `email.list_batches(limit=..., after=..., before=...)`. Domains: sender
232
+ addresses with `email.domains.list_senders(domain_id=..., limit=..., after=..., before=...)`,
233
+ `create_sender({"address": ..., "display_name": ...})`, `get_sender(id)`,
234
+ `update_sender(id, {"display_name": ...})` and `delete_sender(id)`.
235
+ `replay_delivery` delivers one event again with the same event id, and `flush`
236
+ delivers the deliveries held while a webhook was suspended (with
237
+ `include_failed`, also the ones that failed for good); both need the
238
+ webhook enabled (`409` otherwise). `retry` sends a failed email again on
239
+ the same id (an email that can't be retried is a `409` saying why); it
240
+ sends real email, so it takes an idempotency key and generates one when you
241
+ don't pass it. `list_batches` lists your batch sends with the same
242
+ rollup as `get_batch`. A
243
+ sender is a saved From address on one of your domains; saving a mailbox
244
+ that is already saved there is a `409`.
245
+ - Email templates:
246
+ `email.templates.duplicate(id, {"name": ...}, idempotency_key=...)`,
247
+ `email.templates.from_library({"slug": ..., "name": ...}, idempotency_key=...)`,
248
+ `email.templates.usage(id)`,
249
+ `email.templates.list_versions(id, limit=..., after=...)` and
250
+ `email.templates.restore_version(id, version)`.
251
+ `duplicate` copies a template into a new draft, and `from_library` adds a
252
+ gallery email as a draft Design template (the ones marked for paid plans are
253
+ `403 limit_reached` on the free plan); both take an idempotency key and
254
+ generate one when you don't pass it. `usage` says what uses a template and
255
+ whether an edit would be accepted now. `list_versions` pages by version
256
+ number: pass the last row's `version` as `after`. `restore_version` puts a
257
+ version back and is refused with `409` while a live campaign renders the
258
+ template.
259
+ - Type hints: a nullable field typed by a generated model (`Campaign.projected_recipients`, `Campaign.pause_reason`, `Sms.error`) is annotated `X | None` inside its TypedDict entry rather than as a nested string. Nothing changes at runtime.
260
+ - Inbox conversations: a new `email.threads` resource with
261
+ `list(q=..., limit=..., after=...)`, `get(id)`, `delete(id)` and
262
+ `reply(id, body, idempotency_key=...)`. A conversation is a received message
263
+ plus the replies and forwards sent from it, as Emails → Received shows them.
264
+ `list` pages with `next_cursor` (pass it as `after`; it is not a row id);
265
+ `delete` erases the received messages for good. `reply` replies, replies all or forwards one received
266
+ message and sends real email, so it takes an idempotency key and generates
267
+ one when you don't pass it.
268
+ - Email campaigns: `email.campaigns.stats(id)`,
269
+ `email.campaigns.list_stats(ids)`,
270
+ `email.campaigns.list_recipients(id, status=..., limit=..., after=...)`,
271
+ `email.campaigns.list_affected(id)`, `email.campaigns.remove_affected(id)`
272
+ and `email.campaigns.request_review(id)`. SMS campaigns:
273
+ `sms.campaigns.list_recipients(id, limit=..., after=..., before=..., q=...)`.
274
+ `stats` reads a campaign's results: delivered, unique opens and clicks,
275
+ unsubscribes, bounces, complaints and their rates. `list_stats` reads them
276
+ for up to 100 campaigns at once. On an email campaign, `list_recipients`
277
+ lists who a send now would reach and why any other member would be left out;
278
+ pass the page's `next_cursor` as `after` for the next page. After an
279
+ automatic quality pause, `list_affected` lists the hard-bounced and
280
+ complained addresses, `remove_affected` takes them out of the campaign's
281
+ static segment, and `request_review` asks for the review a repeat pause
282
+ needs before `resume`. Both are safe to repeat: a second call removes no one
283
+ and notifies no one. On an SMS campaign, `list_recipients` lists how each
284
+ recipient fared, with `skipped_by_reason` counts for the whole campaign.
285
+ - Contacts: `contacts.addresses(id_or_email)`,
286
+ `contacts.activity(id_or_email, limit=...)`,
287
+ `contacts.list_segments(id_or_email)` and
288
+ `contacts.retry_import(id)`. SMS:
289
+ `sms.request_sms_opt_in(contact_id, {"phone": ...}, idempotency_key=...)`.
290
+ `request_sms_opt_in` texts the contact a
291
+ request to reply YES to confirm marketing texts. It sends a real text, so it
292
+ sends the idempotency key you pass, or one it makes up, and a retry returns
293
+ the same text instead of sending another.
294
+ - Contacts carry `phone`, their SMS number in E.164, on create, update and
295
+ read. `null` on update removes the number only with the `Unitpost-Strict: true` header; without it the number is kept and the response warns. Setting it records no SMS
296
+ consent: record that with `sms.record_sms_consent`.
297
+ - `contacts.list` now takes keyword filters: it and `contacts.list_all` take
298
+ `q`, `status` (`subscribed` | `unsubscribed`), `phone` (`has` | `none`),
299
+ `segment_id` and `segment_subscription` (`subscribed` | `opted_out`);
300
+ `email.list` / `email.list_all` take `to` and `contact_id`.
301
+ - Email and SMS campaigns: `unschedule(id)` and `duplicate(id, {"name": ...}, idempotency_key=...)`. Unschedule moves a scheduled campaign
302
+ back to a draft; duplicate copies a campaign into a new draft. Duplicate
303
+ sends the idempotency key you pass, or one it makes up, so a retry returns
304
+ the same copy instead of making a second one.
305
+ - The campaign update model takes `name`, `subject`, `from`, `preview_text`,
306
+ `template_id` and `segment_id`: the API now edits these on a draft.
307
+ - The email campaign and segment lists take the optional `archived` query
308
+ parameter (`archived=true` lists archived rows).
309
+ - The API now answers `422` for a misnamed send time (`send_at`,
310
+ `scheduledAt` on SMS, …) on sends and campaign writes, instead of sending at
311
+ once or dropping it. Use `scheduled_at`.
312
+ - Campaign create's `403` now says which refusal it is: `limit_reached` for
313
+ the plan's contact limit, `domain_not_found` / `domain_blocked` /
314
+ `domain_not_verified` for the sender (it was always `domain_not_verified`).
315
+ Read `error.code` to tell them apart.
316
+ - Domains: the update model takes `capabilities` (`{ receiving: "enabled" |
317
+ "disabled" }` turns receiving on or off), and domain reads carry
318
+ `capabilities` and a `receiving` object (status, the MX record to publish,
319
+ the last checks).
320
+
321
+ ## 0.4.0
322
+
323
+ The release this changelog starts from. Earlier changes are in the git history
324
+ (tags `sdk-python-v*`).
@@ -0,0 +1,264 @@
1
+ Metadata-Version: 2.5
2
+ Name: unitpost
3
+ Version: 0.5.0
4
+ Summary: Official Unitpost SDK for Python — send email and manage contacts, segments, campaigns, templates, brand kits, domains, suppressions, webhooks, and usage.
5
+ Project-URL: Homepage, https://www.unitpost.com
6
+ Project-URL: Documentation, https://www.unitpost.com/docs
7
+ Project-URL: Repository, https://github.com/unitpostcom/unitpost
8
+ Project-URL: Issues, https://github.com/unitpostcom/unitpost/issues
9
+ Author: Unitpost
10
+ License: MIT
11
+ Keywords: api,email,sdk,transactional-email,unitpost
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Requires-Python: >=3.8
16
+ Requires-Dist: httpx>=0.28.1
17
+ Requires-Dist: typing-extensions>=4.16.0
18
+ Provides-Extra: dev
19
+ Requires-Dist: mypy>=2.3.0; extra == 'dev'
20
+ Requires-Dist: pytest>=9.1.1; extra == 'dev'
21
+ Requires-Dist: respx>=0.23.1; extra == 'dev'
22
+ Description-Content-Type: text/markdown
23
+
24
+ # unitpost
25
+
26
+ Official [Unitpost](https://www.unitpost.com) SDK for Python. Send email and manage
27
+ contacts, segments, campaigns, templates, domains, suppressions, and webhooks.
28
+
29
+ ## Install
30
+
31
+ ```bash
32
+ pip install unitpost
33
+ ```
34
+
35
+ Requires Python 3.8+.
36
+
37
+ ## Quick start
38
+
39
+ ```python
40
+ from unitpost import Unitpost
41
+
42
+ unitpost = Unitpost() # reads UNITPOST_API_KEY (or pass Unitpost("up_..."))
43
+
44
+ result = unitpost.email.send({
45
+ "from": "Acme <you@yourdomain.com>", # bare address works too
46
+ "to": "customer@example.com",
47
+ "subject": "Hello",
48
+ "html": "<p>It works!</p>",
49
+ })
50
+
51
+ if result.error:
52
+ print(result.error.code, result.error.message)
53
+ else:
54
+ print("sent", result.data["id"])
55
+ ```
56
+
57
+ Every method returns a `Result` with `.data` and `.error`. An API-level failure
58
+ populates `.error` (a `UnitpostError`) instead of raising.
59
+
60
+ ## Authentication
61
+
62
+ Pass the key to `Unitpost(...)`, or set `UNITPOST_API_KEY`. Create a key at
63
+ [unitpost.com → Settings → API keys](https://www.unitpost.com).
64
+
65
+ ## Organization keys
66
+
67
+ A platform that gives each of its customers a workspace uses an organization
68
+ key (`ok_live_...`) with the second client, `UnitpostOrganization`. It takes the
69
+ key and the organization's id (`org_...`), and reads `UNITPOST_ORG_KEY` and
70
+ `UNITPOST_ORGANIZATION_ID` when you leave them out:
71
+
72
+ ```python
73
+ from unitpost import Unitpost, UnitpostOrganization
74
+
75
+ org = UnitpostOrganization() # or UnitpostOrganization("ok_live_...", "org_...")
76
+
77
+ workspace = org.workspaces.create({"name": "Acme Bakery", "external_id": "cust_42"}).data
78
+ minted = org.workspace_keys.create(workspace["id"], {"name": "Production", "scope": "sending"}).data
79
+
80
+ # Work inside that workspace with its own key.
81
+ acme = Unitpost(minted["key"])
82
+ ```
83
+
84
+ | Accessor | Covers |
85
+ | --- | --- |
86
+ | `workspaces` | `list()` (`external_id` filter), `list_all()`, `create()` (takes an idempotency key), `get()`, `update()`, `close()`, `restore()` |
87
+ | `workspace_keys` | `create(workspace_id, body)`: mint a workspace key; the secret is in that answer only |
88
+ | `webhooks` | The organization's endpoints (events from every workspace, each with `workspace_id` and `external_id`): `list()`, `list_all()`, `create()`, `get()`, `update()`, `delete()`, `rotate_secret()`, `test()`, `list_deliveries()` (needs `organizations:write`), `list_all_deliveries()`, `replay_delivery()`, `flush()`, `verify()` |
89
+ | `usage` | `list(period=...)`, `list_all()`: usage per workspace for its billing period |
90
+ | `plan_quotes` | Change a workspace's plan: `create()` prices it, `get()`, `confirm()` applies and charges it (takes an idempotency key) |
91
+ | `shared_plan` | The organization's shared plan: `get()`, `list_workspaces()`, `add_workspace()`, `update_workspace()` (its cap), `remove_workspace()` (adding and removing take an idempotency key) |
92
+
93
+ Each client takes one kind of key: the organization client only calls
94
+ `/organizations/{id}/...` routes, and the API answers `401` to an organization
95
+ key on any other route. An Owner or Admin makes the key in the dashboard under
96
+ Organization → API.
97
+
98
+ ## Client surface
99
+
100
+ | Accessor | Covers |
101
+ | --- | --- |
102
+ | `email` | Send, batch, list, get, update, stats, one email's delivery events (`list_events()`), inbound (`received_*`; the original `.eml` with `received_raw()`), retry a failed email (`retry()`, takes an idempotency key), batches (`list_batches()`, `get_batch()`, `cancel_batch()`) |
103
+ | `email.topics` | Topics + contact topic prefs |
104
+ | `email.campaigns` | Draft, schedule, send, pause/resume, results (`stats()`, `list_stats()`), who a send would reach (`list_recipients()`), quality-pause recovery (`list_affected()`, `remove_affected()`, `request_review()`) |
105
+ | `email.templates` | Template CRUD, `duplicate()`, add from the gallery (`from_library()`), what uses it (`usage()`), history (`list_versions()`, `restore_version()`), render it without sending (`render()`, which lists `missing_variables`) |
106
+ | `email.domains` | Domains + verify, `diagnose()`, saved From addresses (`list_senders()`, `create_sender()`, `get_sender()`, `update_sender()`, `delete_sender()`) |
107
+ | `email.threads` | Inbox conversations: `list()` (`q`; page with `next_cursor`), `get()`, `delete()`, `reply()` (reply, reply all or forward; takes an idempotency key) |
108
+ | `sms` | Send, get, list, make the sender of a received text a contact (`add_contact()`, which needs `contacts:write`), `brands()`, a brand (`create_brand()`, which takes an idempotency key, `get_brand()`, `update_brand()`; the writes need `sms:manage`), `numbers()`, one number (`get_number()`), a toll-free verification carriers sent back (`resubmit_number()`, takes an idempotency key), release a number (`release_number()`, PERMANENT: its fee ends and it can't be had back; `{"force": True}` releases it although campaigns are scheduled on it or texts are queued through it; takes an idempotency key and needs `sms:manage`), a number's text-to-join keywords (`list_join_keywords()`, `add_join_keyword()`, `remove_join_keyword()`; the writes need `sms:manage`), a brand's documents (`list_brand_documents()`, `add_brand_document()` with a `file_id` or `text` (takes an idempotency key), `get_brand_document()`, `remove_brand_document()`, `brand_document_url()`, a 5-minute signed link), contact SMS consent, `request_sms_opt_in()` (reply-YES confirmation). Available on paid plans: on the free plan `send` returns a `403` with code `limit_reached`, while the reads keep working. |
109
+ | `sms.templates` | Template CRUD, what uses it (`usage()`), one test text to a simulator number or a verified number from `sms.test_destinations` (`test_send()`, billed like any text; takes an idempotency key) |
110
+ | `sms.messaging_programs` | What a sender registration says your texts are for: `list()` (`archived=True` includes archived ones), `create()` and `duplicate()` (each takes an idempotency key), `get()`, `update()`, `delete()` (archives). The writes need `sms:manage` |
111
+ | `sms.test_destinations` | Verified test numbers: `list()`, `delete()` (needs `sms:manage`). Adding and verifying one stays in the dashboard |
112
+ | `sms.consent_setups` | Where and how people opt in to your texts: `list()` |
113
+ | `sms.billing` | Recurring SMS charges: `list_resources()` |
114
+ | `sms.registrations` | Carrier registrations and their review state: `list()`, `get()`, a 10DLC campaign carriers sent back (`resubmit()`), a failed number whose fee is committed (`request_number()`), take down a 10DLC setup with no number (`remove()`), archive an approved brand registration to register it again (`replace()`); the writes take an idempotency key and need `sms:manage` |
115
+ | `sms.quotes` | Buy carrier resources (register a 10DLC brand, vet it, register a campaign, order a number): `create()` prices the order and returns a single-use `confirm_token`; `confirm()` places it (takes an idempotency key; one is generated when you don't pass one). The confirm needs `sms:purchase`, which no key preset includes, and the owner's monthly cap for SMS purchases by API. Show the person the price first. Release a number with `sms.release_number()` |
116
+ | `contacts` | CRUD, list filters, import jobs (start, cancel, retry), addresses, recent activity, the segments it is in (`list_segments()`; add or remove it with `segments.add_member()` / `segments.remove_member()`), export to CSV (`export()`, a background job) |
117
+ | `contact_fields` | Custom field definitions |
118
+ | `segments` | Segments + membership, opt a member in or out (`update_member()`), who it reaches (`preview()`, and `preview_filter()` for an unsaved filter), the managed all-contacts segment (`all_contacts()`) |
119
+ | `brand_kits` | Brand Kit profiles: `list()`, `get()`, `create()`, `update()`, `delete()`, `reset()`, `set_default()`, `add_graphic()`, and imports from a website or the brand's own words (`import_()`, `get_import()`, `accept_import()`, `cancel_import()`). The writes and starting, accepting or canceling an import need the `branding:write` capability, which no key preset grants |
120
+ | `library_images` | The image library templates embed (`/img/…` paths): `list()`, `list_all()`, `create()` (takes an idempotency key), `get()`, `update()`, `delete()` (`force=True` deletes an image in use) |
121
+ | `files` | Files handed to the API for one purpose and used by `file_id` (a brand document, SMS opt-in evidence, an image): `list()` (`purpose` filters), `create()` (a `url`, base64 `data`, or an upload session; takes an idempotency key), `get()`, `delete()`, and `upload(path_or_bytes, purpose=..., content_type=...)`, which sends up to 3 MB inline and a larger file through an upload session. A file expires 24 hours after it is created |
122
+ | `branding` | The email footer and unsubscribe page look: `get()`, `update()`, `set_logo()`, `remove_logo()`. The writes need the `branding:write` capability, which no key preset grants |
123
+ | `workspace` | Who is calling and what it may do (`whoami()`, any credential), the activity log (`list_activity()`, `list_all_activity()`; needs `activity:read`), and the workspace's name and image: `update()`, `set_image()`, `remove_image()`. Those three need `branding:write`. No key preset grants either capability |
124
+ | `webhooks` | Endpoints + `verify()`, the delivery log (`list_deliveries()`), replay one delivery (`replay_delivery()`), deliver the backlog (`flush()`) |
125
+ | `api_keys` | `list()` and a key's last 24 hours (`usage()`), which need `apikeys:read` (on no key preset); `create()` and `delete()` need a dashboard session |
126
+ | `logs` | The API request log, newest first: `list()` (each call's method, path, status, duration, key and request id; never the IP or a body; kept 30 days). Filters: `status`, `api_key_id`, `method`, `path_prefix`, `request_id`, `created_after` / `created_before`. Needs `apikeys:read` (on no key preset) |
127
+ | `suppressions` | Suppression list |
128
+ | `jobs` | Background jobs: `list()`, `get()`, `cancel()`, `retry()`, a finished job's file (`download()`) |
129
+ | `usage` | Billing-period usage snapshot |
130
+ | `spend_caps` | `get()`, `update()`: the monthly spend cap on SMS purchases made with a key or an app and what it counted this month; `update()` needs `spend_caps:write`, which no key preset grants |
131
+
132
+ ## Pagination
133
+
134
+ ```python
135
+ for contact in unitpost.contacts.list_all():
136
+ print(contact["email"])
137
+ ```
138
+
139
+ ## Suppressions
140
+
141
+ The suppression list holds addresses excluded from every send — single, batch,
142
+ and campaign, including cc/bcc — case-insensitively. Hard bounces and spam
143
+ complaints are added automatically; you can also add your own:
144
+
145
+ ```python
146
+ # Suppress one address, or many in a single call (idempotent — re-adding is a no-op).
147
+ unitpost.suppressions.create({"email": "bounced@example.com", "reason": "manual"})
148
+ unitpost.suppressions.create({"emails": ["a@example.com", "b@example.com"]})
149
+
150
+ # Look one up by id or email; list your own; un-suppress.
151
+ unitpost.suppressions.get("bounced@example.com")
152
+ for s in unitpost.suppressions.list_all():
153
+ print(s["email"], s["reason"])
154
+ unitpost.suppressions.delete("bounced@example.com")
155
+ ```
156
+
157
+ `reason` accepts `manual`, `import`, or `api` — the engine-written `bounce` and
158
+ `complaint` reasons are read-only. Unitpost-wide (`platform`) entries are visible
159
+ but can't be removed via the API.
160
+
161
+ ## Verifying webhooks
162
+
163
+ ```python
164
+ from unitpost import verify_webhook
165
+
166
+ event = verify_webhook(
167
+ payload=raw_body, # the raw request body (str or bytes)
168
+ secret=os.environ["UNITPOST_WEBHOOK_SECRET"],
169
+ headers=request.headers,
170
+ )
171
+ ```
172
+
173
+ Or from the client:
174
+
175
+ ```python
176
+ event = client.webhooks.verify(payload=raw_body, secret=secret, headers=request.headers)
177
+ ```
178
+
179
+ ## Receive a text and answer it
180
+
181
+ US toll-free, 10DLC and Canadian numbers take replies (`two_way: True` on
182
+ `sms.numbers()`). Subscribe a webhook to `sms.received`, skip STOP and texts
183
+ Unitpost already answered, read the conversation with `participant`, and answer
184
+ without `from` so the reply leaves from the number they texted.
185
+
186
+ ```python
187
+ import os
188
+ from unitpost import Unitpost, verify_webhook
189
+
190
+ unitpost = Unitpost() # reads UNITPOST_API_KEY
191
+
192
+ # Your webhook endpoint, subscribed to sms.received. Pass the RAW body.
193
+ def on_webhook(raw_body: bytes, headers: dict) -> None:
194
+ event = verify_webhook(
195
+ payload=raw_body,
196
+ secret=os.environ["UNITPOST_WEBHOOK_SECRET"], # whsec_…
197
+ headers=headers,
198
+ )
199
+ if event["type"] != "sms.received":
200
+ return
201
+ reply = event["data"]
202
+ if reply["keyword"] == "OPT_OUT" or reply["auto_replied"]:
203
+ return # STOP, or already answered
204
+
205
+ # The whole conversation with this person, both directions, newest first.
206
+ # Other filters: direction, status, from_ (sent as `from`), to, contact_id,
207
+ # campaign_id, created_after, created_before.
208
+ history = unitpost.sms.list(participant=reply["from"], limit=20)
209
+ answer = your_agent(history.data["data"], reply["body"] or "")
210
+
211
+ # No "from": the answer goes out from the number they texted.
212
+ unitpost.sms.send({"to": reply["from"], "body": answer})
213
+ ```
214
+
215
+ ## Idempotency
216
+
217
+ `email.send` and `email.batch` are safe to retry by default — if you don't pass
218
+ `idempotency_key`, the SDK generates one so an automatic retry can't double-send.
219
+ Pass your own to dedupe across separate calls:
220
+
221
+ ```python
222
+ unitpost.email.send({...}, idempotency_key="...")
223
+ unitpost.email.batch([...], idempotency_key="...")
224
+ ```
225
+
226
+ > The server dedupes on `(workspace, idempotency key)` for 24h and replays the
227
+ > original result instead of re-sending (the email id for a send, the full list
228
+ > envelope for a batch).
229
+
230
+ ## Retries
231
+
232
+ Transient failures are retried automatically: `429`, `5xx`, and transport errors
233
+ (timeouts / network) retry up to `max_retries` times (default `2`). A `429`/`503`
234
+ `Retry-After` is honored; otherwise exponential backoff with full jitter is used.
235
+ Client errors (`401`/`403`/`404`/`409`/`422`) are never retried. Only requests
236
+ safe to replay are retried: `GET`s and writes carrying an idempotency key (which
237
+ `email.send` and `email.batch` always do); any other keyless write is never
238
+ auto-retried.
239
+
240
+ ```python
241
+ # Defaults shown; set max_retries=0 to disable.
242
+ unitpost = Unitpost(max_retries=2, retry_base_delay=0.5, max_retry_delay=20.0)
243
+ ```
244
+
245
+ ## Resources
246
+
247
+ | | |
248
+ | --- | --- |
249
+ | Docs + API reference | https://www.unitpost.com/docs |
250
+ | Product guides | https://www.unitpost.com/guides |
251
+ | SMTP | https://www.unitpost.com/docs/smtp |
252
+ | OpenAPI JSON | https://www.unitpost.com/api/v1/openapi.json |
253
+ | LLM index | https://www.unitpost.com/llms.txt |
254
+ | Dashboard / API keys | https://www.unitpost.com |
255
+ | Email components (`@unitpost/email`) | https://www.unitpost.com/components |
256
+ | Template gallery | https://www.unitpost.com/templates/gallery |
257
+ | Playground | https://www.unitpost.com/playground |
258
+ | Migration Assistant | https://www.unitpost.com/migration |
259
+ | MCP + Agent Skills | https://www.unitpost.com/docs/ai/mcp · https://www.unitpost.com/docs/ai/skills |
260
+ | Support | support@unitpost.com |
261
+
262
+ ## License
263
+
264
+ MIT