Posthawk Python SDK
The official Python SDK for Posthawk — send transactional emails, schedule deliveries, and manage email jobs.
Install
pip install posthawk
Quick Start
from posthawk import Posthawk
client = Posthawk("ck_live_...")
result = client.emails.send(
from_email="hi@yourdomain.com",
to="user@example.com",
subject="Hello from Posthawk",
html="<h1>Welcome!</h1><p>Your account is ready.</p>",
)
if result.error:
print(result.error.message)
else:
print(f"Sent! Job ID: {result.data.job_id}")
Send Email
result = client.emails.send(
from_email="hi@yourdomain.com",
to=["alice@example.com", "bob@example.com"],
cc="manager@example.com",
subject="Weekly Report",
html="<h1>Report</h1>",
text="Plain text fallback",
headers={"X-Custom": "value"},
metadata={"campaign": "onboarding"},
tags={"type": "transactional"},
)
Schedule Emails
from datetime import datetime, timedelta, timezone
result = client.emails.send(
from_email="hi@yourdomain.com",
to="user@example.com",
subject="Reminder",
text="Don't forget your appointment tomorrow!",
scheduled_for=datetime.now(timezone.utc) + timedelta(hours=24),
)
print(f"Scheduled for: {result.data.scheduled_for}")
Check Delivery Status
result = client.emails.get("job-id-here")
if not result.error:
print(f"Status: {result.data.status}")
# pending | processing | completed | failed
Manage Scheduled Emails
# List all scheduled emails
result = client.scheduled.list(status="scheduled", limit=10)
for email in result.data.data:
print(f"{email.subject} → {email.scheduled_for}")
# Get a specific scheduled email
result = client.scheduled.get("scheduled-email-id")
# Cancel before it sends
result = client.scheduled.cancel("scheduled-email-id")
# Reschedule to a new time
result = client.scheduled.reschedule(
"scheduled-email-id",
scheduled_for="2026-04-01T10:00:00Z",
)
Self-Hosted
Point the SDK at your own Posthawk instance:
client = Posthawk("ck_live_...", base_url="https://api.yourdomain.com")
Error Handling
SDK methods never raise exceptions for API errors. Every method returns a PosthawkResponse with .data and .error:
result = client.emails.send(
from_email="hi@yourdomain.com",
to="user@example.com",
subject="Test",
html="<p>Hello</p>",
)
if result.error:
print(f"Error {result.error.status_code}: {result.error.message}")
else:
print(f"Success: {result.data.job_id}")
Context Manager
Use a context manager to automatically close the HTTP connection pool:
with Posthawk("ck_live_...") as client:
result = client.emails.send(
from_email="hi@yourdomain.com",
to="user@example.com",
subject="Hello",
html="<h1>Hi</h1>",
)
API Reference
| Method | Description |
|---|---|
client.emails.send(...) |
Send an email or schedule one |
client.emails.get(job_id) |
Check delivery status |
client.scheduled.list(...) |
List scheduled emails |
client.scheduled.get(id) |
Get a scheduled email |
client.scheduled.cancel(id) |
Cancel a scheduled email |
client.scheduled.reschedule(id, ...) |
Reschedule an email |
License
MIT
Metadata
Release files for posthawk 0.7.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| posthawk-0.7.0.tar.gz | 15.5 kB | Without provenance | Details for posthawk-0.7.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| posthawk-0.7.0-py3-none-any.whl | Python 3 | none | any | Details for posthawk-0.7.0-py3-none-any.whl |
Total release size: 38.0 kB
Release files / posthawk-0.7.0.tar.gz
| Download URL | posthawk-0.7.0.tar.gz |
|---|---|
| Size | 15.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cda493b89ecaf2400f792d10ad5f255e3bf6513ed57a8a64eed84bfc5e706411
|
|
BLAKE2b-256 checksum How to use checksums |
c39bce6ac419225430050bb571c27103d04efc813336d22a5051ffd394d84f68
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.0
|
Release files / posthawk-0.7.0-py3-none-any.whl
| Download URL | posthawk-0.7.0-py3-none-any.whl |
|---|---|
| Size | 22.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5e0de191b259b07e17cb6053aed27fd974f28db0b48e3b0e219f950cd5c6abb3
|
|
BLAKE2b-256 checksum How to use checksums |
d0784ca81a34c47650af6e22e983e13fc489f5958f47ffdc57906f56f4eba57a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.0
|
Security for posthawk 0.7.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.