Skip to main content

Official Python SDK for SendPigeon - Transactional Email API

Project description

SendPigeon Python SDK

Official Python SDK for SendPigeon - Transactional Email API.

Installation

pip install sendpigeon

Quick Start

from sendpigeon import SendPigeon

client = SendPigeon("sk_live_xxx")

# Send an email
result = client.send(
    to="user@example.com",
    subject="Welcome!",
    html="<h1>Hello!</h1><p>Welcome to our service.</p>"
)

if result.ok:
    print(f"Email sent: {result.data.id}")
else:
    print(f"Error: {result.error.message}")

Async Support

from sendpigeon import AsyncSendPigeon

async with AsyncSendPigeon("sk_live_xxx") as client:
    result = await client.send(
        to="user@example.com",
        subject="Hello",
        html="<p>Hi there!</p>"
    )

Local Development

Use the SendPigeon CLI to catch emails locally:

# Terminal 1: Start local server
npx @sendpigeon-sdk/cli dev

# Terminal 2: Run your app with dev mode
SENDPIGEON_DEV=true python app.py

When SENDPIGEON_DEV=true, the SDK routes requests to localhost:4100 instead of production.

Features

Send Email

result = client.send(
    to="user@example.com",       # or ["a@x.com", "b@x.com"]
    subject="Hello",
    html="<p>HTML content</p>",
    text="Plain text fallback",
    from_="hello@yourdomain.com",
    reply_to="support@yourdomain.com",
    cc="cc@example.com",
    bcc="bcc@example.com",
    tags=["welcome", "onboarding"],
    metadata={"user_id": "123"},
    scheduled_at="2024-01-15T10:00:00Z",
)

Templates

# Use a template
result = client.send(
    to="user@example.com",
    template_id="tmpl_xxx",
    variables={"name": "John", "company": "Acme"},
)

# Manage templates
templates = client.templates.list()
template = client.templates.create(
    name="Welcome Email",
    subject="Welcome, {{name}}!",
    html="<p>Hi {{name}}, welcome to {{company}}!</p>"
)

Batch Sending

result = client.send_batch([
    {"to": "a@example.com", "subject": "Hi A", "html": "<p>Hello A</p>"},
    {"to": "b@example.com", "subject": "Hi B", "html": "<p>Hello B</p>"},
])

print(f"Sent: {result.data.summary['sent']}, Failed: {result.data.summary['failed']}")

Domains

# List domains
domains = client.domains.list()

# Add and verify a domain
domain = client.domains.create("yourdomain.com")
print(f"Add these DNS records: {domain.data.dns_records}")

# Check verification
verification = client.domains.verify(domain.data.id)
print(f"Verified: {verification.data.verified}")

API Keys

# Create a new API key
key = client.api_keys.create(
    name="Production",
    mode="live",
    permission="sending",  # or "full_access"
)
print(f"Save this key: {key.data.key}")  # Only shown once!

# List keys
keys = client.api_keys.list()

Webhook Verification

from sendpigeon import verify_webhook

result = verify_webhook(
    payload=request.body,
    signature=request.headers["X-Webhook-Signature"],
    timestamp=request.headers["X-Webhook-Timestamp"],
    secret="whsec_xxx",
)

if result.valid:
    event = result.payload
    print(f"Event: {event['type']}")

Error Handling

The SDK uses a Result pattern - no exceptions are thrown for API errors:

result = client.send(to="user@example.com", subject="Hi", html="<p>Hello</p>")

if result.error:
    print(f"Error: {result.error.message}")
    print(f"Code: {result.error.code}")      # "api_error", "network_error", "timeout_error"
    print(f"API Code: {result.error.api_code}")  # e.g., "DOMAIN_NOT_VERIFIED"
    print(f"Status: {result.error.status}")  # HTTP status code
else:
    print(f"Success: {result.data.id}")

# Or use unwrap() for quick scripts (raises on error)
email = client.send(...).unwrap()

Configuration

client = SendPigeon(
    "sk_live_xxx",
    base_url="https://api.sendpigeon.dev",  # Override API URL
    timeout=30.0,                            # Request timeout in seconds
    max_retries=2,                           # Retry failed requests (0-5)
    debug=True,                              # Log requests/responses
)

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

sendpigeon-0.3.2.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

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

sendpigeon-0.3.2-py3-none-any.whl (19.7 kB view details)

Uploaded Python 3

File details

Details for the file sendpigeon-0.3.2.tar.gz.

File metadata

  • Download URL: sendpigeon-0.3.2.tar.gz
  • Upload date:
  • Size: 14.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for sendpigeon-0.3.2.tar.gz
Algorithm Hash digest
SHA256 59ceb869a56ea7041738f2d8e0d20f4f6f04ef6f5d4f74833a56ef84ce87252b
MD5 3e0ed54c3d5332fa314df61f1469eac5
BLAKE2b-256 484b51761f3d23cdac9e94ed8bda2ce9df18c53c6b922f94c6796b1db962b18f

See more details on using hashes here.

File details

Details for the file sendpigeon-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: sendpigeon-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 19.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for sendpigeon-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 705217ac10bd8a03f978afbf5ec9919bd564d2b618f1f6f8da80c56cc32761b9
MD5 302365699117393d51f4e4fe4128deb5
BLAKE2b-256 8c23508cae010481d76970404b834ab0de87dc03b84eb973a3e05691a6c43ed9

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