SDKs
Python SDK
Send transactional emails from Django, Flask, FastAPI, and other Python frameworks with the Postkit Python SDK
The Postkit Python SDK is coming soon. In the meantime, use the REST API directly -- it takes under 5 minutes to get started.
Installation
pip install postkitpoetry add postkitQuick start
from postkit import Postkit
client = Postkit("pk_live_abc123...")
email = client.emails.send(
from_address="Acme <noreply@acme.eu>",
to=["user@example.com"],
subject="Welcome to Acme",
html="<h1>Welcome!</h1><p>Thanks for signing up.</p>",
)
print(email.id) # em_...The Python SDK uses from_address instead of from since from is a reserved keyword in Python.
Send with a template
email = client.emails.send(
from_address="Acme <noreply@acme.eu>",
to=["user@example.com"],
subject="Order Confirmation",
template_id="tmpl_abc123",
template_data={
"order_id": "12345",
"total": "49.99",
},
)Send a batch
result = client.emails.send_batch([
{
"from": "Acme <noreply@acme.eu>",
"to": ["alice@example.com"],
"subject": "Welcome",
"html": "<p>Welcome, Alice!</p>",
},
{
"from": "Acme <noreply@acme.eu>",
"to": ["bob@example.com"],
"subject": "Welcome",
"html": "<p>Welcome, Bob!</p>",
},
])
# result.data contains per-email resultsDomains
# List domains
domains = client.domains.list()
# Verify a domain
verification = client.domains.verify("dom_abc123")Webhooks
# Create a webhook
webhook = client.webhooks.create(
url="https://example.com/webhooks/postkit",
events=["email.delivered", "email.bounced"],
)
# Verify a webhook signature
from postkit import verify_webhook_signature
is_valid = verify_webhook_signature(
payload=payload,
signature=headers["webhook-signature"],
secret=webhook.signing_secret,
)Async support
from postkit import AsyncPostkit
client = AsyncPostkit("pk_live_abc123...")
email = await client.emails.send(
from_address="Acme <noreply@acme.eu>",
to=["user@example.com"],
subject="Welcome",
html="<p>Hello!</p>",
)Available resources
| Resource | Methods |
|---|---|
client.emails | send(), send_batch(), get(), list(), cancel() |
client.domains | create(), list(), get(), verify(), delete() |
client.templates | create(), list(), get(), update(), delete(), publish(), preview() |
client.webhooks | create(), list(), get(), update(), delete(), rotate_secret() |
client.suppressions | create(), list(), get(), delete() |
client.inbound | list(), get() |
client.api_keys | create(), list(), get(), update(), delete() |
For full endpoint documentation, see the API Reference.