Send product email from Python. Sync or async, with one trace.
Send transactional email and publish lifecycle events from sync and async Python services with the Send & Retain API.
✓Use the Python SDK, requests, or httpx without changing the API contract.
One request, complete trace
Request
POST /api/v1/emails
Authorization: Bearer aem_…
Idempotency-Key: welcome-8f21
{ "to": "[email protected]", "template": "welcome" }
202 Accepted
{ "id": "msg_7ca31", "status": "queued" }
[ 01 / 04 ]Client contract
Fit email into the Python service you already run.
Use the official Python client
Install with pip or uv, or call the same HTTP API directly with httpx or requests.
Send typed payloads
Sender, recipients, template, and props as plain typed values — no dashboard coupling.
Handle delivery events
Read the raw request body for signature verification before your framework deserialises it.
[ 02 / 04 ]Server quickstart
Queue one email from Python.
One call, one message ID, one delivery timeline.
Use an async HTTP client when this runs inside an async framework.
response = requests.post(
"https://sendandretain.com/api/v1/emails",
headers={"Authorization": f"Bearer {os.environ['AEM_KEY']}",
"Idempotency-Key": f"welcome-{user.id}"},
json={"to": user.email, "template": "welcome"}, timeout=10,
)
response.raise_for_status()Accepted response
{ "id": "msg_7ca31", "status": "queued" }[ 03 / 04 ]Quickstart
Choose the execution model your service already uses.
Reuse one HTTP client
Load the key from server configuration and share a requests session or async client.
Call from the right boundary
Queue inline for simple services or from Celery, RQ, or your existing worker for retried work.
Keep the accepted ID
Attach the message identifier to your job or domain event for later delivery checks.
Production checklist
- Secrets stay server-side
- Timeout and retry policy
- Idempotent webhook handler
- Structured error logging
[ 04 / 04 ]Related
Use Python in context
Questions people ask us
Queue your first Python email.
Pick sync or async, keep the accepted ID, and verify the delivery outcome.