Official Python SDK for the Drin transactional email API.
Project description
drin
Official Python SDK for the Drin transactional email API. Zero dependencies (standard library only), typed, Python 3.8+.
Install
pip install drin
Quick start
from drin import DrinClient
drin = DrinClient(api_key="drin_...") # or os.environ["DRIN_API_KEY"]
res = drin.emails.send({
"from": {"email": "you@send.drin.run", "name": "Acme"},
"to": [{"email": "user@example.com"}],
"subject": "Welcome",
"html": "<h1>Welcome</h1>",
"text": "Welcome",
})
print(res["id"], res["status"])
The client defaults to https://api.drin.run; override with base_url.
Request bodies are plain dicts whose keys match the REST API; responses are
parsed JSON.
Tenant-wide keys
A tenant-wide key must name the sender (its externalId):
drin = DrinClient(api_key, sender="customer_42")
# or per request:
drin.emails.send(body, sender="customer_42")
Idempotency
drin.emails.send(body, idempotency_key="order-1234") # honored 24h, per sender
Pagination
Every list endpoint returns {"data": [...], "nextCursor": ...}. Use
paginate(...) to walk every page lazily:
for message in drin.emails.paginate({"status": "delivered"}):
print(message["id"])
Typed errors
from drin import DrinRateLimitError, DrinSuppressedError, DrinError
try:
drin.emails.send(body)
except DrinRateLimitError as e:
time.sleep(e.retry_after or 1)
except DrinSuppressedError:
... # all recipients suppressed
except DrinError as e:
print(e.type, e.status, e.code)
Webhook verification
Verify the Drin-Signature header on inbound webhooks. Pass the raw request
body. Pure local check — no network call.
from drin import verify_webhook, DrinWebhookVerificationError
# e.g. in a Flask/Django/FastAPI handler:
raw_body = request.get_data(as_text=True) # the exact bytes received
signature = request.headers["Drin-Signature"]
try:
result = verify_webhook(raw_body, signature, signing_secret, tolerance_seconds=300)
event = result.payload # trusted only AFTER verification
except DrinWebhookVerificationError:
abort(400)
Resources
drin.emails · drin.domains · drin.inboxes · drin.threads ·
drin.inbound · drin.webhooks · drin.suppressions · drin.api_keys ·
drin.metrics · drin.templates · drin.contacts · drin.forms — one method
per /v1 endpoint.
A first-party TypeScript SDK is also available: npm install @drin/sdk.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file drin-0.1.0.tar.gz.
File metadata
- Download URL: drin-0.1.0.tar.gz
- Upload date:
- Size: 19.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
def9d80a07407e2d3c89dac94ce2cb9324c33f64ce50269615c3eed69a3dad98
|
|
| MD5 |
4e812c4ae75bdb97ee4a0e6ac776099e
|
|
| BLAKE2b-256 |
379d8570250d2f03b115e53b1d6f00addbcc7f8e6cd131be25c6fd3e5362b5cd
|
File details
Details for the file drin-0.1.0-py3-none-any.whl.
File metadata
- Download URL: drin-0.1.0-py3-none-any.whl
- Upload date:
- Size: 17.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dbe2eb6303baff6c1bcd5cc0510254615e1a6ce0c00be8d31ae0a69eb02ffbd3
|
|
| MD5 |
531336b8b94249a8e21e89047463fb49
|
|
| BLAKE2b-256 |
5f0f24f35bd6e7b0e6e288e26afbab17cd4f91bdf3b49046be4688085594b818
|