Skip to main content

Zemail Python SDK

Latest Version on PyPI GitHub Tests Action Status Python Version License

The official Python SDK for the Zemail Developer API. Create and manage temporary mailboxes, receive emails, and handle attachments programmatically.


Requirements

  • Python 3.9 or higher
  • httpx >= 0.24.0
  • pydantic >= 2.0.0

Installation

Install the package via pip:

pip install zemail-python

Or install the latest development version directly from GitHub:

pip install git+https://github.com/zemailme/zemail-python.git

Quickstart

Initialize the ZemailClient with your API key:

from zemail import ZemailClient

client = ZemailClient(api_key="zm_live_your_api_key_here")

You can optionally specify an API version, timeout, custom headers, or use it as a context manager:

from zemail import ZemailClient

with ZemailClient(
    api_key="zm_live_your_api_key_here",
    version="2026-04-23",
    timeout=10.0,
    headers={"X-Custom-Header": "value"},
) as client:
    account = client.account.get()
    print(f"Logged in as: {account.email}")

Usage

1. Account & Subscription

Access your account profile, active subscription plan, and API/mailbox usage limits:

# Get account profile
account = client.account.get()
print(f"Account ID: {account.id}, Email: {account.email}, Tier: {account.tier}")

# Get active subscription
subscription = client.account.subscription()
print(f"Status: {subscription.status}, Tier: {subscription.tier}")

# Get current resource & API usage
usage = client.account.usage()
print("Mailbox Usage:", usage.mailboxes)
print("Storage Usage:", usage.storage)
print("Developer API Usage:", usage.developer_api)

2. Domains

List available domains for mailbox creation:

domains = client.domains.list()

for domain in domains.data:
    print(f"Domain: {domain.name} (Types: {', '.join(domain.allowed_types)})")

3. Mailboxes

List Mailboxes

mailboxes = client.mailboxes.list(page=1, limit=10)

for mailbox in mailboxes.data:
    print(f"Mailbox: {mailbox.address} (ID: {mailbox.id})")

if mailboxes.has_more:
    print(f"Next cursor: {mailboxes.next_cursor}")

Create a Random Mailbox

mailbox = client.mailboxes.create(type="random")
print(f"Created random mailbox: {mailbox.address}")

Create a Custom Mailbox

mailbox = client.mailboxes.create(
    type="custom",
    domain="zemail.me",
    username="my-inbox",
)
print(f"Created custom mailbox: {mailbox.address}")

Get Mailbox Details

mailbox = client.mailboxes.get(mailbox_id=123)
print(f"Address: {mailbox.address}, Unread emails: {mailbox.unread_count}")

Delete a Mailbox

deleted = client.mailboxes.delete(mailbox_id=123)
print(f"Mailbox deleted: {deleted.deleted}")

4. Emails & Attachments

List Emails in a Mailbox

# List emails with optional search query and pagination
emails = client.emails.list(
    mailbox_id=mailbox.id,
    page=1,
    limit=25,
    search="verification",
)

for email in emails.data:
    print(f"[{email.id}] From: {email.sender} | Subject: {email.subject}")

Tip: You can also access email methods via client.mailboxes.emails:

emails = client.mailboxes.emails.list(mailbox_id=mailbox.id)

Get Full Email Details

email = client.emails.get(mailbox_id=mailbox.id, email_id=email_id)

print(f"Subject: {email.subject}")
print(f"Plain text body: {email.body_text}")
print(f"HTML body: {email.body_html}")

# Inspect attachments
for attachment in email.attachments:
    print(f"Attachment: {attachment.name} ({attachment.size} bytes)")

Mark Email as Read

read_state = client.emails.mark_as_read(mailbox_id=mailbox.id, email_id=email_id)
print(f"Is read: {read_state.is_read}")

Get Temporary Attachment Download URL

download = client.emails.get_attachment_download_url(
    mailbox_id=mailbox.id,
    email_id=email_id,
    attachment_id="att_123",
)

print(f"Download URL: {download.url}")
print(f"Expires at: {download.expires_at}")

Delete an Email

deleted = client.emails.delete(mailbox_id=mailbox.id, email_id=email_id)
print(f"Email deleted: {deleted.deleted}")

Error Handling

All SDK exceptions inherit from ZemailAPIError (which subclasses ZemailError):

Exception HTTP Status Description
AuthenticationError 401 Invalid API key or unauthorized access
PermissionError 403 Forbidden action or insufficient permissions
NotFoundError 404 Resource (mailbox, email, domain) not found
ValidationError 422 Request validation failure (includes e.errors)
InvalidRequestError 400, 422 Malformed or invalid request parameters
RateLimitError 429 Daily or concurrency rate limit reached
ZemailAPIError Any Generic API exception
ZemailError Any Base SDK exception
from zemail import (
    AuthenticationError,
    NotFoundError,
    RateLimitError,
    ValidationError,
    ZemailAPIError,
    ZemailClient,
)

client = ZemailClient(api_key="zm_live_...")

try:
    mailbox = client.mailboxes.create(type="custom")
except ValidationError as e:
    print(f"Validation failed: {e.message}")
    print("Errors:", e.errors)
except AuthenticationError as e:
    print(f"Auth error: {e.message}")
except RateLimitError as e:
    print(f"Rate limited: {e.message}")
except NotFoundError as e:
    print(f"Not found: {e.message}")
except ZemailAPIError as e:
    print(f"API error [{e.status}]: {e.message}")

Development & Testing

Run unit tests with pytest:

pytest

Run linting and type checks with ruff:

ruff check .
ruff format --check .

Format code with ruff:

ruff format .

License

The MIT License (MIT). Please see LICENSE for more information.

Download files

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

Source Distribution

zemail_python-1.0.0.tar.gz (15.1 kB view details)

Uploaded Source

Built Distribution

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

zemail_python-1.0.0-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file zemail_python-1.0.0.tar.gz.

File metadata

  • Download URL: zemail_python-1.0.0.tar.gz
  • Upload date:
  • Size: 15.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.5

File hashes

Hashes for zemail_python-1.0.0.tar.gz
Algorithm Hash digest
SHA256 cd1c2dcaf384dbe538e8d423454ed9e825f86d1b36115f0068de50976a660b67
MD5 4e0051cccb24faae21ede3fd2573e685
BLAKE2b-256 1954caac48dc36c134aa2da5f869e78d27fd0a5ef9bb66feb2db42d8b1a86bc2

See more details on using hashes here.

File details

Details for the file zemail_python-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: zemail_python-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.5

File hashes

Hashes for zemail_python-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9e9d0d6ad9a4651711568444c4d11a1aac8312ddbd6e2e482b28ab28a912356d
MD5 5661498c22171b1dcf38da8e7e5dfbf1
BLAKE2b-256 c7d7662bc2640491130090c786f76225f7a81f4ca60c597cada9ad6001151193

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 Sentry Error logging StatusPage Status page