Skip to main content

A lightweight Python client for the ZeptoMail transactional email API.

Project description

ZeptoMail

PyPI version Python versions License: MIT

A lightweight Python client for the ZeptoMail transactional email API.

Features

  • Simple, Pythonic API for sending transactional emails
  • Support for HTML and plain-text email bodies
  • File attachments with MIME type validation
  • Reply-to and bounce address support
  • Proper error handling with custom exceptions
  • Fully typed (PEP 561 compatible)
  • Zero configuration — just add your API key

Installation

pip install zeptomail

Quick Start

from zeptomail import Config, Email

config = Config(api_key="your-zeptomail-api-key")
email = Email(config, bounce_address="bounce@yourdomain.com")

response = email.send(
    from_="noreply@yourdomain.com",
    from_name="My Application",
    to=["user@example.com"],
    subject="Welcome!",
    html_body="<h1>Hello!</h1><p>Welcome to our platform.</p>",
)

print(response)

Usage

Configuration

from zeptomail import Config

# Basic configuration
config = Config(api_key="your-api-key")

# With custom timeout
config = Config(api_key="your-api-key", timeout=60)

Sending Emails

from zeptomail import Config, Email

config = Config(api_key="your-api-key")
email = Email(config)

# Simple text email
response = email.send(
    from_="noreply@yourdomain.com",
    from_name="Sender Name",
    to=["recipient@example.com"],
    subject="Hello!",
    text_body="This is a plain text email.",
)

# HTML email to multiple recipients
response = email.send(
    from_="noreply@yourdomain.com",
    from_name="Sender Name",
    to=["alice@example.com", "bob@example.com"],
    subject="Newsletter",
    html_body="<h1>Monthly Update</h1><p>Here's what's new...</p>",
)

# Using recipient dicts for custom display names
response = email.send(
    from_="noreply@yourdomain.com",
    from_name="Sender Name",
    to=[
        {"address": "alice@example.com", "name": "Alice"},
        {"address": "bob@example.com", "name": "Bob"},
    ],
    subject="Hello!",
    html_body="<p>Hi there!</p>",
)

Attachments

from zeptomail import Config, Email, MimeType
from zeptomail.utils import file_to_base64

config = Config(api_key="your-api-key")
email = Email(config)

# Attach a file
content = file_to_base64("/path/to/report.pdf")
mime = MimeType("application", "pdf")

response = email.send(
    from_="noreply@yourdomain.com",
    from_name="Sender Name",
    to=["recipient@example.com"],
    subject="Your Report",
    text_body="Please find your report attached.",
    attachments=[(content, mime, "report.pdf")],
)

MIME Types

from zeptomail import MimeType

# Create from components
pdf = MimeType("application", "pdf")
png = MimeType("image", "png")

# Parse from string
csv = MimeType.from_string("text/csv")

# Validate
pdf.is_valid()   # True
exe = MimeType("application", "exe")
exe.is_valid()   # False — .exe is blocked by ZeptoMail

Reply-To

response = email.send(
    from_="noreply@yourdomain.com",
    from_name="Sender Name",
    to=["recipient@example.com"],
    subject="Support Ticket #1234",
    text_body="We received your request.",
    reply_to=[("support@yourdomain.com", "Support Team")],
)

Error Handling

from zeptomail import Config, Email, ZeptoMailAPIError

config = Config(api_key="your-api-key")
email = Email(config)

try:
    response = email.send(
        from_="noreply@yourdomain.com",
        from_name="Sender",
        to=["user@example.com"],
        subject="Test",
        text_body="Hello!",
    )
except ZeptoMailAPIError as exc:
    print(f"API error {exc.status_code}: {exc.response_body}")

API Reference

Config(api_key, *, url=None, timeout=30)

Parameter Type Description
api_key str Your ZeptoMail API key.
url str Override the default API endpoint (optional).
timeout int Request timeout in seconds. Default: 30.

Email(config, bounce_address=None)

Parameter Type Description
config Config A Config instance.
bounce_address str Envelope bounce address (optional).

Email.send(...)

Parameter Type Description
from_ str Sender email address.
from_name str Sender display name.
to list[str | dict] Recipient addresses.
subject str Email subject line.
text_body str | None Plain-text body (optional).
html_body str | None HTML body (optional).
reply_to list[tuple[str, str]] Reply-to (email, name) pairs (optional).
attachments list[tuple[str, MimeType, str]] (base64, mime, filename) triples (optional).
client_reference str | None Tracking reference (optional).

MimeType(type_, subtype)

Method / Property Returns Description
.value str MIME string, e.g. "application/pdf".
.is_valid() bool True if not in the blocked list.
.validate() self Returns self or raises MimeTypeError.
.from_string(s) MimeType Class method to parse "type/subtype".

Requirements

License

This project is licensed under the MIT License — see the LICENSE file for details.

Contributing

Contributions are welcome! Please open an issue or pull request on GitHub.

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

zeptomail-0.1.0.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

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

zeptomail-0.1.0-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: zeptomail-0.1.0.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for zeptomail-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1832e86593aa9e36ae422834c4d35e1f753ee32136f90266dbb2b27c5f69e4b3
MD5 7f583eb019fee0b90b7ad6af8b05c78b
BLAKE2b-256 81d7df2fd44dced9d82633fca0a06dbcdfa89a5425f0091a0ee522442bba2554

See more details on using hashes here.

File details

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

File metadata

  • Download URL: zeptomail-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for zeptomail-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b2ba923320e37a3c30c43b007640409ee39c1b97b893a81d8191d07beb5628c2
MD5 83999daf3fbcb74bf56d4a703918be0c
BLAKE2b-256 d8b70c5489ab7cd0095fa53ba09788aa4f76569227dd281c6f5f132e8914754f

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