Python SDK

The official camelmailer package is fully typed, with sync and async clients that share identical signatures, one dependency (httpx), Python 3.9+.

Install

terminal
pip install camelmailer

Quickstart

mailer.py
import camelmailer

client = camelmailer.CamelMailer(api_key="cm_xxxx")  # or set CAMELMAILER_API_KEY
result = client.emails.send({
    "from": "billing@yourdomain.com",
    "to": ["ada@example.com"],
    "subject": "Your receipt",
    "html_body": "<p>Thanks for your purchase!</p>",
})
print(result["message_id"])

The API key is a server API key (header X-Server-API-Key). Every method exists on the AsyncCamelMailer client too, with the same signatures; just await them.

Send with a template

template.py
client.emails.send_with_template({
    "from": "hello@yourdomain.com",
    "to": ["ada@example.com"],
    "template": "welcome",
    "template_model": {"name": "Ada"},
})

Error handling

API errors are typed exceptions carrying the stable code, the message and the HTTP status_code.

errors.py
import camelmailer

try:
    client.emails.send({"from": "no@unverified.example",
                        "to": ["x@example.com"], "subject": "Hi"})
except camelmailer.ValidationError as e:      # also AuthenticationError,
    print(e.code, e.status_code, e.message)   # NotFoundError, RateLimitError
except camelmailer.CamelMailerError as e:     # base class for everything else
    print(e.code)

Self-hosted instances

The default base URL is the cloud (https://app.camelmailer.com). Point the client at your own instance, or set CAMELMAILER_BASE_URL:

self-hosted.py
client = camelmailer.CamelMailer(
    api_key="cm_xxxx",
    base_url="https://mail.yourcompany.com",
)
from is a Python keyword, so pass the payload as a dict as shown above. Full field reference: Messages API.

GitHub repository · PyPI package