Django email backend and webhook consumer for the Clario email API.
Requirements
- Python 3.10+
- Django 4.2+
- Clario API key with
emails:send - Free, Solo, or Pro plan (API included on Free within quotas)
Installation
pip install clario-django
Configuration
# settings.py
EMAIL_BACKEND = "clario.django.email_backend.EmailBackend"
CLARIO_API_KEY = "clario_live_..."
# Optional when Django From matches a Clario address:
# CLARIO_MAIL_ADDRESS_ID = "01HX..."
# CLARIO_MAIL_ADDRESSES = {"noreply@acme.com": "01HX..."}
CLARIO_BASE_URL = "https://clario-mail.com/api/v1"
Send
from django.core.mail import EmailMultiAlternatives
msg = EmailMultiAlternatives(
subject="Welcome",
body="Plain text",
from_email="noreply@acme.com",
to=["user@example.com"],
)
msg.attach_alternative("<p>Welcome</p>", "text/html")
msg.extra_headers["X-Clario-Idempotency-Key"] = "welcome-user-42-v1"
msg.send()
Sender resolution
X-Clario-Mail-Address-Idheader →mail_address_idCLARIO_MAIL_ADDRESSES[from]→mail_address_idCLARIO_MAIL_ADDRESS_ID→mail_address_id- Django
from_email→from(API resolves the mailbox)
Idempotency
Prefer a stable business key via X-Clario-Idempotency-Key or Idempotency-Key.
If omitted, the backend hashes the rendered message so retries of the same content do not double-send.
Webhooks (optional)
CLARIO_WEBHOOKS_ENABLED = True
CLARIO_WEBHOOK_SECRET = "whsec_..."
CLARIO_WEBHOOK_TOLERANCE = 300
# urls.py
from django.urls import include, path
urlpatterns = [
path("clario/", include("clario.webhooks.urls")),
]
Point Clario Developers to https://your-app/clario/webhook.
from django.dispatch import receiver
from clario.webhooks.signals import email_delivered
@receiver(email_delivered)
def on_delivered(sender, event, **kwargs):
# event.email_id, event.data, event.event_id
...
Signatures use Clario-Signature: t=…,v1=… (HMAC-SHA256 of timestamp.rawBody). Invalid signatures return 401.
Attachments
Max 10 files, 5 MB each. Allowed MIME types: PDF, JPEG/PNG/GIF, Word, Excel, CSV, plain text.
Exceptions
clario.exceptions.ClarioApiError exposes status_code, error_code, request_id, and retryable.
Development
pip install -e ".[dev]"
pytest
Publishing
python -m build
twine check dist/*
twine upload dist/*
Tag releases as v0.1.0 (CI can publish on tag).
License
MIT
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 clario_django-0.1.0.tar.gz.
File metadata
- Download URL: clario_django-0.1.0.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
825787adf0eb1094c98e3f38be1d4356cfb89527a224e5281433d477031235cb
|
|
| MD5 |
f036eef1a933124c58f186e0c6c548e0
|
|
| BLAKE2b-256 |
ba71d1d2d3f208b89b5807628817da774ffaa220214bc5db5716ed872f06839d
|
File details
Details for the file clario_django-0.1.0-py3-none-any.whl.
File metadata
- Download URL: clario_django-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b5fc9bdb1eb08e2f9190e3fad4b8b05f18684ec66af57c8c6986114a0e82bc99
|
|
| MD5 |
b80601923f8dcc8f5ac5f0ad3d6afab3
|
|
| BLAKE2b-256 |
731d9d41bca39315c7f10218de6570d4eaabdc0ea582feb21849743b23fba5ea
|