Skip to main content

Official Posthawk SDK for sending emails

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

posthawk-0.1.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

posthawk-0.1.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file posthawk-0.1.0.tar.gz.

File metadata

  • Download URL: posthawk-0.1.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for posthawk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c2443d8d6084a8aa5b8d726547864693fd353a8ed29dc1360c63a6dec5f572c7
MD5 03ddfca06c3daf460318d406863bc22b
BLAKE2b-256 a0d347ca880373eba44716c3cca71386ae2d6ff722dd914471a9457526622fab

See more details on using hashes here.

File details

Details for the file posthawk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: posthawk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for posthawk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 54728356961cb54605ad5455d5cd144852eb2567e9b396f09331c8e91990e3d0
MD5 7507eeed4c4e950525b82ec78efc912d
BLAKE2b-256 a59782e4a03c00150f61aa44a133657afb4de093e224efb3deb62eb1627ff01a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page