Language SDKs
Python
Send published Sendery templates from Python.
pip install sendery==0.1.4Requirements
Python 3.10+.
Set up
Choose a published template and create a project API key. Store the key as SENDERY_API_KEY on your server.
export SENDERY_API_KEY="your_project_api_key"Send an email
Replace your-template with your published template’s key and data with its variables.
The response contains the accepted email’s id and status. Calls are synchronous; use asyncio.to_thread() when sending from async code.
import os
from sendery import Sendery
sendery = Sendery(os.environ["SENDERY_API_KEY"])
receipt = sendery.send(
to="[email protected]",
template="your-template",
data={"name": "Alex", "action_url": "https://example.com/start"},
)
print(receipt["id"])Retrieve an email
Use the returned ID to check delivery status.
message = sendery.get(receipt["id"])
print(message["status"])Retry a send
Use retry(3) for up to three extra attempts after temporary failures. Keep the same idempotency key and email data on every attempt.
email = sendery.prepare(
to="[email protected]",
template="your-template",
data={"name": "Alex", "action_url": "https://example.com/start"},
idempotency_key="your-idempotency-key",
)
receipt = email.retry(3).send()Handle errors
Catch the SDK exception to inspect the status and code. Retry delays are in seconds. The example uses the prepared email from the retry example above.
from sendery import SenderyError
try:
receipt = email.retry(3).send()
except SenderyError as error:
print(error.status, error.code, error.errors)
# error.retry_after is a delay in seconds, when provided.
raiseSend a specific version
Choose a published template version to keep sending it after newer versions are published. By default, Sendery uses the latest version.
receipt = sendery.prepare(
to="[email protected]",
template="your-template",
data={"name": "Alex", "action_url": "https://example.com/start"},
).version(3).send()Attachments
Use attachment() to create an attachment from file bytes. The helper handles base64 encoding.
Send up to 10 files totaling 5 MB. See the attachment reference for supported formats and limits.
from pathlib import Path
from sendery import attachment
file = Path("document.pdf").read_bytes()
sendery.prepare(
to="[email protected]",
template="your-template",
data={"name": "Alex", "action_url": "https://example.com/start"},
idempotency_key="your-idempotency-key",
attachments=[attachment("document.pdf", file, "application/pdf")],
).retry().send()