Skip to main content
The official drin Python client is a thin wrapper over the REST API — with built-in retries, cursor pagination, typed errors, and local webhook signature verification, and zero third-party dependencies (standard library only). The SDK is published to PyPI as drin. It mirrors the wire contract one-to-one, so anything you can do over REST you can do here with the same request and response shapes.
Requirements. Python 3.8+. The SDK has zero third-party dependencies — the default HTTP backend uses the standard-library urllib. You can inject your own backend (requests / httpx) via the http_handler option.

Install

Create a client

Construct one client and reuse it. The only required argument is api_key; pass sender only when you authenticate with a tenant-wide key (see Authentication).
The client exposes one resource per area of the API. Each has the create / get / list / delete methods as appropriate:
  • emails · domains · inboxes · threads · inbound · webhooks
  • suppressions · contacts · templates · api_keys · metrics · forms
Request bodies are plain dicts whose keys match the REST API wire format (camelCase), e.g. {"from": {...}, "to": [...], "templateId": "..."}. Responses are returned as parsed JSON (dict / list).

Send

emails.send() resolves to a dict carrying the message id you can use to retrieve status or reply later.
To pick a verified sending domain in code rather than hard-coding it, use the domains.list_verified() convenience — it auto-pages and returns only the domains a from address may use:
Idempotent sends. Pass idempotency_key to make a retry safe — drin.emails.send(body, idempotency_key="order-42"). It is honored for 24h, per sender. See Idempotency & retries.

Paginate

Every list endpoint returns {"data": [...], "nextCursor": ...}. The easiest way to walk all of it is .paginate(), a lazy iterator that fetches each page and stops when nextCursor is empty — re-using whatever filter you passed:
When you want to control paging yourself — for cursor-based UIs, say — call .list() and thread the cursor:
paginate() is available on emails, domains, threads, contacts, suppressions, templates, webhooks, api_keys, and forms.

Receive & reply

Inbound mail lands on an inbox and is joined into a thread alongside your outbound messages. Reply in one call — Drin handles the addressing and the threading headers, so the recipient’s mail client threads the conversation correctly:

Verify a webhook

Use verify_webhook() (also exposed as drin.webhooks.verify()) — a pure, local check with no network call. Pass the raw request body (the exact bytes you received, before any JSON parsing) and the Drin-Signature header. It returns the verified result on success and raises DrinWebhookVerificationError on any mismatch.
Use the raw body. Most frameworks parse JSON before your handler runs, which re-serializes the bytes and breaks the signature. Capture the raw body (e.g. request.get_data(as_text=True) in Flask) and verify that, not the parsed object.

Typed errors

Every failure is a subclass of DrinError, so you can branch with except or on err.type. The base carries type, status, code, param, request_id, and the raw body.
The full set of typed errors: DrinValidationError, DrinAuthenticationError, DrinPermissionError, DrinNotFoundError, DrinConflictError, DrinSuppressedError, DrinRateLimitError, DrinInternalError, and DrinConnectionError (raised on a network failure, timeout, or abort before any HTTP response was received). The SDK auto-retries 429 and 5xx with exponential backoff and full jitter (default 2 retries). A POST is retried only when you supplied an idempotency_key, so a send is never duplicated. See Errors for the full type table.

Next steps

API reference

Every endpoint, parameter, and response shape the SDK wraps.

Other languages

No Python? Call the same REST API from any stack.

Authentication

Project-scoped vs tenant-wide keys, and the sender option.

Webhooks

Subscribe to delivery, bounce, complaint, open, and click events.