Skip to main content

Official Python SDK for MailBreeze email platform

Project description

MailBreeze Python SDK

The official Python SDK for the MailBreeze email platform.

Features

  • Full async support - Built on httpx for modern async/await patterns
  • Type-safe - Complete type hints with Pydantic models
  • Automatic retries - Built-in retry logic with exponential backoff
  • Python 3.10+ - Modern Python with native type syntax

Installation

pip install mailbreeze

Quick Start

import asyncio
from mailbreeze import MailBreeze

async def main():
    async with MailBreeze(api_key="sk_live_xxx") as client:
        # Send an email
        result = await client.emails.send(
            from_="hello@yourdomain.com",
            to="user@example.com",
            subject="Welcome!",
            html="<h1>Welcome to our platform!</h1>",
        )
        print(result.message_id)  # msg_xxx

asyncio.run(main())

Resources

Emails

# Send an email
result = await client.emails.send(
    from_="hello@yourdomain.com",
    to="user@example.com",
    subject="Hello",
    html="<p>Hello World!</p>",
)
print(result.message_id)  # msg_xxx

# Send with a template
result = await client.emails.send(
    from_="hello@yourdomain.com",
    to=["user1@example.com", "user2@example.com"],
    template_id="welcome-template",
    variables={"name": "John", "plan": "Pro"},
)

# Send with attachments
result = await client.emails.send(
    from_="hello@yourdomain.com",
    to="user@example.com",
    subject="Document attached",
    html="<p>Please find the attachment.</p>",
    attachment_ids=["att_xxx"],
)

# List emails
emails = await client.emails.list(status="delivered", page=1, limit=20)
for email in emails.data:
    print(email.id, email.status)

# Get email details
email = await client.emails.get("email_xxx")
print(email.status, email.delivered_at)

# Get statistics
stats = await client.emails.stats()
print(stats.success_rate)  # 98.5
print(stats.total)  # 1500

Contact Lists

# Create a list
list_ = await client.lists.create(
    name="Newsletter Subscribers",
    description="Weekly newsletter recipients",
)
print(list_.id)

# List all lists
lists = await client.lists.list()
for lst in lists.data:
    print(lst.name)

# Get a list
list_ = await client.lists.get("list_xxx")

# Update a list
list_ = await client.lists.update("list_xxx", name="Updated Name")

# Get list stats
stats = await client.lists.stats("list_xxx")
print(stats.total_contacts)
print(stats.active_contacts)

# Delete a list
await client.lists.delete("list_xxx")

Contacts

# Get contacts for a list
contacts = client.contacts("list_xxx")

# Create a contact
contact = await contacts.create(
    email="user@example.com",
    first_name="John",
    last_name="Doe",
    custom_fields={"company": "Acme Inc"},
)
print(contact.id)

# List contacts
result = await contacts.list(status="active", page=1, limit=50)
for contact in result.data:
    print(contact.email)

# Get a contact
contact = await contacts.get("contact_xxx")

# Update a contact
updated = await contacts.update("contact_xxx", first_name="Jane")

# Suppress a contact (opt-out)
await contacts.suppress("contact_xxx", reason="unsubscribed")

# Delete a contact
await contacts.delete("contact_xxx")

Email Verification

# Verify a single email
result = await client.verification.verify({"email": "user@example.com"})
print(result.is_valid)  # True
print(result.is_deliverable)  # True

# Batch verification (async processing)
batch = await client.verification.batch(["user1@example.com", "user2@example.com"])
print(batch.verification_id)  # ver_xxx
print(batch.status)  # "processing"

# Check batch status
status = await client.verification.get(batch.verification_id)
print(status.status)  # "completed"
print(status.results)

# List all verifications
verifications = await client.verification.list()

# Get verification statistics
stats = await client.verification.stats()
print(stats.total_valid)
print(stats.valid_percentage)

Attachments

# Create a pre-signed upload URL
upload = await client.attachments.create_upload(
    filename="document.pdf",
    content_type="application/pdf",
    size=1024000,  # bytes
)
print(upload.attachment_id)  # att_xxx
print(upload.upload_url)  # Pre-signed URL

# Upload the file to the pre-signed URL (use your preferred HTTP client)
# httpx.put(upload.upload_url, content=file_bytes)

# Confirm the upload
attachment = await client.attachments.confirm(upload.attachment_id)
print(attachment.status)  # "ready"

Error Handling

from mailbreeze import (
    MailBreeze,
    MailBreezeError,
    AuthenticationError,
    ValidationError,
    NotFoundError,
    RateLimitError,
    ServerError,
)

try:
    result = await client.emails.send(
        from_="hello@yourdomain.com",
        to="user@example.com",
        subject="Hello",
        html="<p>Hello</p>",
    )
except ValidationError as e:
    print(f"Validation failed: {e.message}")
    print(f"Details: {e.details}")
except AuthenticationError:
    print("Invalid API key")
except RateLimitError as e:
    print(f"Rate limited. Retry after {e.retry_after} seconds")
except NotFoundError:
    print("Resource not found")
except ServerError as e:
    print(f"Server error: {e.status_code}")
except MailBreezeError as e:
    print(f"API error: {e.code} - {e.message}")

Configuration

from mailbreeze import MailBreeze

client = MailBreeze(
    api_key="sk_live_xxx",
    base_url="https://api.mailbreeze.com/api/v1",  # Optional
    timeout=30.0,  # Request timeout in seconds
    max_retries=3,  # Retry attempts for retryable errors
)

Requirements

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

mailbreeze-0.2.7.tar.gz (21.4 kB view details)

Uploaded Source

Built Distribution

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

mailbreeze-0.2.7-py3-none-any.whl (20.8 kB view details)

Uploaded Python 3

File details

Details for the file mailbreeze-0.2.7.tar.gz.

File metadata

  • Download URL: mailbreeze-0.2.7.tar.gz
  • Upload date:
  • Size: 21.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mailbreeze-0.2.7.tar.gz
Algorithm Hash digest
SHA256 c1ddc651a0296507af0ff56022e2851568ddb3f58346732777fe4d65b4f98238
MD5 91efcef92dff6abc453dc83490a773ae
BLAKE2b-256 9f32fdd0d71a7952eff4c14aabbfcb4e364e71fa7d3fb9db750748de0b3b92a1

See more details on using hashes here.

Provenance

The following attestation bundles were made for mailbreeze-0.2.7.tar.gz:

Publisher: release.yml on MailBreeze/mailbreeze-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mailbreeze-0.2.7-py3-none-any.whl.

File metadata

  • Download URL: mailbreeze-0.2.7-py3-none-any.whl
  • Upload date:
  • Size: 20.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mailbreeze-0.2.7-py3-none-any.whl
Algorithm Hash digest
SHA256 482cf0e5b107303b4f0d74c444985647416c24ed4de694d52d78d3d5491a3ccf
MD5 4cf8c5860f026db86ca85eb90436c98c
BLAKE2b-256 2cc4ce8a17e806ec0af50f84c8c7fc00a3bd3e6a79ee01e1ffec73103dadad7f

See more details on using hashes here.

Provenance

The following attestation bundles were made for mailbreeze-0.2.7-py3-none-any.whl:

Publisher: release.yml on MailBreeze/mailbreeze-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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