Skip to content
Sendtier Docs
Dashboard

Python SDK

Send email and verify webhooks with the sync and async Python clients.

The Python SDK requires Python 3.11 or newer. Version 0.1.0 is not yet published. Before publication, install from a local checkout with pip install ./sdk/python. After publication:

pip install sendtier==0.1.0

Send an email

Add your sending domain and set SENDTIER_API_KEY to your test or live key. Test emails are accepted but never delivered; live sending requires verified DNS.

import os
from sendtier import Sendtier

with Sendtier(os.environ["SENDTIER_API_KEY"]) as client:
    email = client.emails.send({
        "from": "hello@mail.example.com",
        "to": ["user@example.com"],
        "subject": "Hello",
        "text": "Your first email.",
    }, idempotency_key="welcome-user-123")
    print(email["id"])

The clients call /v1 paths on https://api.sendtier.com, such as POST /v1/emails. Every request sends Authorization: Bearer. The API major version is fixed by the paths; there is no version option. Use base_url to point at a local API.

For async code, use async with AsyncSendtier(...) and await client.emails.send(...). List helpers follow cursors automatically. Pass an idempotency_key to reuse the same request safely. Idempotent POSTs retry HTTP 429, HTTP 5xx and transport failures up to three times. Errors raise SendtierError with a code, hint and request ID.

Verify webhooks

Read the exact request body bytes before parsing JSON. Use the complete whsec_ secret and the Sendtier-Signature header. Reject the callback if verify_webhook raises SendtierError; a successful call returns None.

import json
import os
from sendtier import verify_webhook

# raw_body and signature_header come from your HTTP server request.
verify_webhook(os.environ["SENDTIER_WEBHOOK_SECRET"], signature_header, raw_body)
event = json.loads(raw_body)

Deduplicate events by ID. See webhooks for payloads, signature rotation and delivery retries. The API reference describes request and response fields; the sending guide covers idempotency.

On this page