Skip to main content

Postmarker

Build Coverage Version Python versions Docs License

Python client for the Postmark email API.

Postmarker covers Postmark's API beyond sending: templates, bounces, suppressions, message streams, stats, servers and domains. It also ships a Django email backend, Postmark webhook wrappers and a pytest fixture for your tests.

Installation

uv pip install postmarker

To inline <style> CSS into HTML emails, install the css-inline extra and create the client with inline_css=True:

uv pip install 'postmarker[css-inline]'

Usage

from postmarker.core import PostmarkClient

postmark = PostmarkClient(server_token="POSTMARK_API_TEST")
postmark.emails.send(
    From="sender@example.com",
    To="receiver@example.com",
    Subject="Postmark test",
    HtmlBody="<strong>Hello</strong> dear Postmark user.",
)
# {"ErrorCode": 0, "Message": "Test job accepted", "MessageID": "...", ...}

With the POSTMARK_API_TEST token, Postmark validates the request without delivering it. To send real emails, use the server token from your server's API Tokens tab in Postmark. From must be a confirmed sender signature or an address on a verified domain.

Send with a template:

postmark.emails.send_with_template(
    TemplateAlias="welcome",
    TemplateModel={"name": "Jane"},
    From="sender@example.com",
    To="receiver@example.com",
)

Send a batch. Postmarker splits it into requests of 500 messages, Postmark's limit:

messages = [
    {"From": "sender@example.com", "To": to, "Subject": "Hi", "TextBody": "Hello"}
    for to in ("first@example.com", "second@example.com")
]
responses = postmark.emails.send_batch(*messages)
# Postmark accepts or rejects each message separately
failed = [response for response in responses if response["ErrorCode"] != 0]

Add headers and attachments:

email = postmark.emails.Email(
    From="sender@example.com",
    To="receiver@example.com",
    Subject="Report",
    TextBody="See the attached report.",
)
email["X-Accept-Language"] = "en-us, en"
email.attach("/home/user/report.pdf")
email.attach_binary(content=b"content", filename="readme.txt")
email.send()

A rejected request raises ClientError with Postmark's error code:

from postmarker.exceptions import ClientError

try:
    postmark.emails.send(
        From="sender@example.com",
        To="receiver@example.com",
        TextBody="Hello",
    )
except ClientError as exc:
    print(exc.error_code)  # For example, 406 for an inactive recipient

A request without a usable Postmark response, e.g. a network error, a timeout or an HTML 502 from a proxy, raises TransportError, the same in the sync and async clients. status_code is the HTTP status when there was a response, and the original requests or httpx2 exception is in __cause__.

Async

AsyncPostmarkClient has the same API, with every method that makes a request as a coroutine. Install the async extra:

uv pip install 'postmarker[async]'
from postmarker.core import AsyncPostmarkClient

async with AsyncPostmarkClient(server_token="POSTMARK_API_TEST") as postmark:
    await postmark.emails.send(
        From="sender@example.com",
        To="receiver@example.com",
        TextBody="Hello",
    )

See the async guide for properties, fixtures and differences.

Django

Django 6.1+:

MAILERS = {
    "default": {
        "BACKEND": "postmarker.django.EmailBackend",
        "OPTIONS": {"token": "<YOUR POSTMARK SERVER TOKEN>"},
    },
}

Django 5.2 and 6.0:

EMAIL_BACKEND = "postmarker.django.EmailBackend"
POSTMARK = {"TOKEN": "<YOUR POSTMARK SERVER TOKEN>"}

Django then sends send_mail, EmailMessage and emails from third-party apps through Postmark. The Django guide covers tags, metadata, message streams and signals.

Testing

Postmarker ships a postmark_request pytest fixture. It mocks requests to Postmark and records what your code sent, through PostmarkClient or the Django backend:

def test_welcome_email(postmark_request):
    send_welcome_email("jane@example.com")  # Your code that sends an email
    assert postmark_request.call_args.kwargs["json"]["To"] == "jane@example.com"

Features

  • Server APIs: Emails, Templates with layouts, Bounces, Messages (inbound, outbound, opens and clicks), Message Streams, Suppressions, Server, Stats and Triggers.
  • Account APIs: Domains, Sender signatures, Servers and pushing templates between servers.
  • Status and Spam check APIs.
  • Webhook wrappers: Inbound, Delivery, Open, Click, Bounce, Spam complaint and Subscription change.
  • Sending email.message.Message instances.
  • CSS inlining via css-inline.
  • Async client (AsyncPostmarkClient) via the async extra.
  • Django email backend and Tornado helper.
  • Type annotations, with a py.typed marker.

Documentation

https://postmarker.readthedocs.io/en/stable/

Python support

Postmarker supports CPython 3.11 to 3.15 and PyPy 3.11. The Django email backend supports Django 5.2, 6.0 and 6.1.

Metadata

Release files for postmarker 4.0.2

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

Source distribution (sdist)

Source distribution for postmarker 4.0.2
File Size Uploaded Provenance Actions
postmarker-4.0.2.tar.gz 86.9 kB With provenance Details for postmarker-4.0.2.tar.gz

Built distribution (wheel)

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

Total release size: 127.0 kB

Release files / postmarker-4.0.2.tar.gz

Download URL postmarker-4.0.2.tar.gz
Size 86.9 kB
Tags Source
SHA-256 checksum
How to use checksums
67ab9963d3c7ab0be027892d483a32387d7bc301d503fd910f286a037215bf58
BLAKE2b-256 checksum
How to use checksums
47d3af6a4838fbff3f9013d32162a862f2e8f34ad395ada9d5b472a57e7e0fe1
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 Dec 1, 2026.

Transparency log

Release files / postmarker-4.0.2-py3-none-any.whl

Download URL postmarker-4.0.2-py3-none-any.whl
Size 40.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fed513a8d50db59964936dd331bceb777c3bcc1dd039bf8fa0f5752d4144d951
BLAKE2b-256 checksum
How to use checksums
cbee6956e6787f39bad8cb9cd8258258f5a801936b45d9df097505be0adb5899
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 Dec 1, 2026.

Transparency log

Security for postmarker 4.0.2

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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for postmarker-4.0.2.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 Dec 1, 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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

4.0.2 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