Skip to main content

SMTPfast Python SDK

The official Python SDK for the SMTPfast API. It covers every endpoint in the API, sync and async, with types for every request and response. It needs Python 3.10+ and depends only on httpx.

pip install smtpfast

Send an email

from smtpfast import SMTPfast

client = SMTPfast()  # reads SMTPFAST_API_KEY

email = client.emails.send({
    "from": "Acme <hello@yourdomain.com>",
    "to": ["customer@example.org"],
    "subject": "Your receipt",
    "html": "<p>Thanks for your order.</p>",
    "category": "transactional",
})
print(email["id"])

Email is marketing unless you set category to transactional. Marketing email gets a one-click unsubscribe header and is not sent to people who unsubscribed. Set transactional on receipts, password resets and account alerts so a marketing opt-out does not block them.

Requests and responses are plain dicts, typed with TypedDicts from smtpfast.types, so your editor and type checker know every field. A new field or value from the API never breaks your code, because the SDK does not validate responses at runtime.

Every API operation is a method, named after its path: client.domains.verify(id), client.contacts.segments.add(contact_id, segment_id), client.inboxes.threads.emails.reply(inbox_id, thread_id, email_id, params). Path parameters come first, then the request body, and query parameters are keyword arguments: client.emails.list(limit=20, status="bounced").

Async

from smtpfast import AsyncSMTPfast

async with AsyncSMTPfast() as client:
    await client.emails.send({...})

Options

client = SMTPfast(
    api_key="sf_...",            # default: SMTPFAST_API_KEY
    base_url="https://smtpfa.st/api",
    max_retries=2,                # after 429 (with Retry-After), 408, 5xx and dropped connections
    timeout=60.0,                 # per attempt, in seconds
)

client.emails.send(params, idempotency_key="order-1234", options={"timeout": 10})

Retries and idempotency

Reads, PUT and DELETE are retried after a 5xx answer or a dropped connection. A send, reply or forward is retried with the same Idempotency-Key, so the API returns the first answer instead of sending twice. When you do not give a key, the SDK makes one per call. Other POST and PATCH calls are retried only after a per-second rate limit, which the API rejects before doing any work.

Errors

Every error is an SMTPfastError. An answer outside 2xx raises an APIError with status, body and headers, as one of BadRequestError, AuthenticationError, PermissionDeniedError, NotFoundError, ConflictError, UnprocessableEntityError, RateLimitError or InternalServerError. No answer at all raises APIConnectionError or APITimeoutError.

import smtpfast

try:
    client.emails.get("em_missing")
except smtpfast.NotFoundError as err:
    print(err.status, err.body)

Pagination

Lists that page with a cursor also have a ..._all method that fetches the next pages as you iterate:

for email in client.emails.list_all(limit=100):
    print(email["id"], email["status"])

Webhooks

from smtpfast import webhooks

# The raw body, before any JSON parsing.
event = webhooks.parse(request.body, request.headers, secret=os.environ["SMTPFAST_WEBHOOK_SECRET"])
if event["type"] == "email.bounced":
    ...

webhooks.verify_signature(payload, signature, secret) returns a bool if you only need the check.

How this SDK is made

The SDK is generated from the OpenAPI document, so it follows the API without hand edits. scripts/generate.py (standard library only) writes src/smtpfast/types.py and src/smtpfast/_resources.py, naming every method from the x-sdk-group and x-sdk-method the spec gives each operation; the SDKs for other languages use the same names. _core.py, _errors.py and webhooks.py are written by hand.

python scripts/pull_spec.py   # download the published spec into spec/openapi.json
python scripts/generate.py    # regenerate types.py and _resources.py
pytest -q                     # unit tests, including one call per operation
SMTPFAST_API_KEY=sf_... pytest tests/test_live.py   # read-only calls, checked against the spec

A daily workflow pulls the spec and opens a pull request when it changed.

License

MIT

Metadata

Release files for smtpfast 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for smtpfast 0.1.0
File Size Uploaded Provenance
smtpfast-0.1.0.tar.gz 91.9 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for smtpfast 0.1.0
File Interpreter ABI Platform
smtpfast-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 125.2 kB

Release files / smtpfast-0.1.0.tar.gz

Download URL smtpfast-0.1.0.tar.gz
Size 91.9 kB
Tags Source
SHA-256 checksum
How to use checksums
0771057a6cf3a86ea39f00e860c85d3ab23d7ac3f81f23c9db17d5fe9e71fdb9
BLAKE2b-256 checksum
How to use checksums
466fff7dfc4acc5c28eb3b87d8872e9cdeac88f53027eb22dcaef88fffbdbe6d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.

Transparency log

Release files / smtpfast-0.1.0-py3-none-any.whl

Download URL smtpfast-0.1.0-py3-none-any.whl
Size 33.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
047c621bb61d21c67a7d9f8fba6e1b88c6050c33e5451e71c86689038fd715bb
BLAKE2b-256 checksum
How to use checksums
8901a608cc87e95fe48e42d21a8a18ff3890ea29bd4c1f6d618245a7e923a3f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.

Transparency log

Security for smtpfast 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for smtpfast-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page