Cherami Python SDK
The official Python client for Cherami, email infrastructure for AI agents. Create inboxes for your agents, read the mail that arrives and send from their addresses.
Python 3.11+, with synchronous and asynchronous clients and typed dictionaries.
Install and connect
pip install cherami
# or
uv add cherami
Create an API key and supply it privately as CHERAMI_API_KEY. Then list your inboxes:
import os
from cherami import Cherami
with Cherami(os.environ["CHERAMI_API_KEY"]) as client:
for inbox in client.list_inboxes().data["inboxes"]:
print(inbox["id"], inbox["address"])
This prints every inbox on your account. Set CHERAMI_INBOX_ID to the one you want to work with; the examples below use it. If the list is empty, create an inbox with create_inbox.
Methods take a dictionary and return a response envelope: .data holds the result, and .status, .headers and .request_id the HTTP details. Path and query parameters go at the top level of the dictionary, and JSON request fields go in body. Field names match the HTTP API. Leave out optional fields you don't need, and pass None only where the API accepts null.
Read mail
List recent messages, then fetch each one. Its content is available once processing_status is ready:
with Cherami(os.environ["CHERAMI_API_KEY"]) as client:
page = client.list_messages({
"inbox_id": os.environ["CHERAMI_INBOX_ID"], "limit": 20,
}).data
for message in page["messages"]:
detail = client.get_message({"message_id": message["id"]}).data
if detail["processing_status"] == "ready":
print(detail["content"]["text"])
else:
print(detail["id"], detail["processing_status"])
To act on mail as it arrives, add a webhook, or poll as Receive and poll for mail describes.
Async and pagination
AsyncCherami has the same methods and response types. iterate reads across pages without you managing cursors:
import asyncio
from cherami import AsyncCherami
async def main():
async with AsyncCherami(os.environ["CHERAMI_API_KEY"]) as client:
async for message in client.iterate("list_messages", {
"inbox_id": os.environ["CHERAMI_INBOX_ID"], "limit": 20,
}, max_pages=5):
detail = (await client.get_message({"message_id": message["id"]})).data
if detail["processing_status"] == "ready":
print(detail["content"]["text"])
else:
print(detail["id"], detail["processing_status"])
asyncio.run(main())
The sync client iterates the same way with a plain for. iterate yields items and pages yields response envelopes; both fetch only as you consume them. Set max_pages to cap requests; otherwise they follow every page.
For a long-lived client outside a with block, call close(), or await aclose(), when your application shuts down.
Send and recover
Prepare each email once and save the record before you submit it.
from cherami import prepare_send
intent = prepare_send("send_message", {
"inbox_id": os.environ["CHERAMI_INBOX_ID"],
"body": {
"to": [{"address": "recipient@example.com", "name": "Alex"}],
"subject": "Review ready",
"text": "The change is ready for review.",
},
})
record = intent.to_json()
# Save record here.
Submit the saved record:
from cherami import restore_send
saved = restore_send(record) # the record you saved
with Cherami(os.environ["CHERAMI_API_KEY"]) as client:
receipt = client.submit(saved).data
print(receipt["message"]["id"], receipt["message"]["status"], receipt["outcome_persisted"])
If submit raises CheramiTransportError, the response was lost: submit the same saved record again. It carries the original retry key, so we return the first attempt instead of sending a second email.
receipt["message"]["status"] tells you what happened:
| Outcome | Meaning |
|---|---|
accepted |
The email provider accepted the message. This does not confirm delivery. |
rejected |
The provider refused it, and receipt["message"]["error_code"] says why. Fix that and prepare a new record to send it again. |
unknown |
We couldn't confirm whether it went out. Preparing it again could send a duplicate. |
All three arrive as data, not exceptions. If outcome_persisted is false, keep this receipt: later reads may not show its outcome.
submit accepts a record for 23 hours and 59 minutes after preparation, then raises SendRecoveryExpiredError. After that, check list_sent_messages: if the email isn't there, prepare it again.
prepare_send also takes reply_message, reply_all_message and forward_message. If you call those methods or send_message directly, supply your own idempotency_key and save the request before sending: resending it unchanged within 24 hours returns the first attempt instead of sending again. Drafts send with send_draft and recover by sending the same draft ID again. See the sending guide and draft guide for those workflows.
Handle errors
from cherami import CheramiApiError
with Cherami(os.environ["CHERAMI_API_KEY"]) as client:
try:
inboxes = client.list_inboxes().data
except CheramiApiError as error:
print(error.status, error.code, error.request_id)
API errors also expose .body, .headers and .retry_after. CheramiTransportError means no usable response arrived; for a send, submit the same saved record again.
Each network operation times out after 60 seconds of inactivity by default. Pass timeout to a client or method to change it, or None to disable it. The client never retries a request or follows a redirect.
More workflows
The SDK also covers sent mail, replies, forwarding, drafts, labels, conversations, Trash and restore, policy inspection and attachment downloads.
- Runnable examples: read mail, prepare a reply, and submit or recover it.
- Python guide: client configuration, attachments and downloads.
- HTTP reference: every operation's fields and responses.
Named types such as SendInput, SendReceipt and ListMessagesParams are in cherami.models for type checking.
For help, contact support.
Development
You don't need Bun or the model generator to use the package. See CONTRIBUTING.md for generation and distribution details.
MIT licensed.
Metadata
Release files for cherami 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cherami-0.2.0.tar.gz | 91.9 kB | Without provenance | Details for cherami-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cherami-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for cherami-0.2.0-py3-none-any.whl |
Total release size: 111.6 kB
Release files / cherami-0.2.0.tar.gz
| Download URL | cherami-0.2.0.tar.gz |
|---|---|
| Size | 91.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ec26dd1026c01ea8982254af4108266c13f3880bfe148d62952423392705595f
|
|
BLAKE2b-256 checksum How to use checksums |
785b0082b0fabaa519f293eb41c7b567aae862dbd8be301072e72042b7dde847
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.19 {"installer":{"name":"uv","version":"0.12.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / cherami-0.2.0-py3-none-any.whl
| Download URL | cherami-0.2.0-py3-none-any.whl |
|---|---|
| Size | 19.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1926c70310d88adbfcf11a906fb9eb868c85487a58bd22e775c34daca39982d3
|
|
BLAKE2b-256 checksum How to use checksums |
39edd374955536fa5cb0b53d7365d4aa90e651422eb48fb9996585680fa4c0a9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.19 {"installer":{"name":"uv","version":"0.12.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for cherami 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.