Skip to main content

Pigeon transactional email SDK for Python

Project description

Pigeon Python SDK

Official Python SDK for Pigeon - Transactional email made simple.

Installation

pip install roselabs-pigeon

Quick Start

Async Usage (Recommended)

from pigeon import Pigeon

pigeon = Pigeon(api_key="pk_xxx")

# Send using a template
result = await pigeon.send(
    to="user@example.com",
    template_name="welcome-email",
    variables={
        "name": "John",
        "company_name": "Acme Inc",
    },
)

print(f"Email sent! ID: {result.id}")

Sync Usage

from pigeon import PigeonSync

with PigeonSync(api_key="pk_xxx") as pigeon:
    result = pigeon.send(
        to="user@example.com",
        template_name="welcome-email",
        variables={
            "name": "John",
            "company_name": "Acme Inc",
        },
    )

print(f"Email sent! ID: {result.id}")

Sending Emails

Using Templates

# Single recipient
result = await pigeon.send(
    to="user@example.com",
    template_name="order-confirmation",
    variables={
        "order_id": "12345",
        "total": "$99.00",
    },
)

# Multiple recipients
result = await pigeon.send(
    to=["user1@example.com", "user2@example.com"],
    template_name="announcement",
    variables={"message": "Big news!"},
)

Raw Emails

result = await pigeon.send(
    to="user@example.com",
    subject="Hello from Pigeon!",
    html="<h1>Welcome!</h1><p>Thanks for signing up.</p>",
    text="Welcome! Thanks for signing up.",
)

With Options

result = await pigeon.send(
    to="user@example.com",
    template_name="welcome-email",
    variables={"name": "John"},
    from_name="Support Team",
    reply_to="support@yourcompany.com",
)

Managing Templates

# List all templates
templates = await pigeon.list_templates()
for template in templates:
    print(f"{template.name}: {template.subject}")

# Get a specific template
template = await pigeon.get_template_by_name("welcome-email")
print(template.html_content)

Viewing Sent Emails

# List recent emails
emails = await pigeon.list_emails(page=1, page_size=50)
for email in emails.emails:
    print(f"{email.id}: {email.subject} -> {email.to}")

# Get specific email
email = await pigeon.get_email("email-uuid")
print(email.status)

Error Handling

from pigeon import Pigeon, PigeonAPIError, PigeonValidationError

pigeon = Pigeon(api_key="pk_xxx")

try:
    result = await pigeon.send(
        to="user@example.com",
        template_name="nonexistent-template",
        variables={},
    )
except PigeonAPIError as e:
    print(f"API error: {e.status_code} - {e.message}")
except PigeonValidationError as e:
    print(f"Validation error: {e}")

Configuration

pigeon = Pigeon(
    api_key="pk_xxx",
    base_url="https://pigeon.api.roselabs.io",  # Default
    timeout=30.0,  # Request timeout in seconds
)

API Reference

Pigeon (Async Client)

  • send() - Send an email
  • list_templates() - List all templates
  • get_template(id) - Get template by ID
  • get_template_by_name(name) - Get template by name
  • list_emails() - List sent emails
  • get_email(id) - Get email by ID

PigeonSync (Sync Client)

Same methods as Pigeon, but synchronous. Use as a context manager:

with PigeonSync(api_key="pk_xxx") as pigeon:
    result = pigeon.send(...)

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

roselabs_pigeon-0.1.2.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

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

roselabs_pigeon-0.1.2-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file roselabs_pigeon-0.1.2.tar.gz.

File metadata

  • Download URL: roselabs_pigeon-0.1.2.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for roselabs_pigeon-0.1.2.tar.gz
Algorithm Hash digest
SHA256 620a9ad4e9643325a1a024d15c75cfcff0626f45beb06455a58bb137e4c4acdc
MD5 04a7d8ea7bf83071e7d65ae87839d185
BLAKE2b-256 a420828930299a14011aaada819329ae35c4d634c1f048d34207c67322f45fe4

See more details on using hashes here.

File details

Details for the file roselabs_pigeon-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: roselabs_pigeon-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 11.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for roselabs_pigeon-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 87e374c4cbd65d82022e3b982a0464f1d8a649250db11814cb78b1c4c08a4fba
MD5 02fb2d27892816a5bb512f0c9874d916
BLAKE2b-256 4a69503b3bcbd979d462b9171663a4f33aa88c9f13592c902f3666d32aa6d3ba

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