Postmarker
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
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.Messageinstances. - CSS inlining via css-inline.
- Django email backend and Tornado helper.
- Type annotations, with a
py.typedmarker.
Documentation
https://postmarker.readthedocs.io/en/stable/
Python support
Postmarker supports CPython 3.10 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 2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| postmarker-2.1.tar.gz | 72.0 kB | With provenance | Details for postmarker-2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| postmarker-2.1-py3-none-any.whl | Python 3 | none | any | Details for postmarker-2.1-py3-none-any.whl |
Total release size: 105.3 kB
Release files / postmarker-2.1.tar.gz
| Download URL | postmarker-2.1.tar.gz |
|---|---|
| Size | 72.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5d1c5bd6d7165ccc13b2dfa922a0470446b595aa7c492abcdb4b9c7a62d584e1
|
|
BLAKE2b-256 checksum How to use checksums |
d71e1b0ff18777fe0b9aa37fc3b4503c8f09030659417727c37398eb6d1fbe32
|
| 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 Nov 13, 2026.
Transparency logRelease files / postmarker-2.1-py3-none-any.whl
| Download URL | postmarker-2.1-py3-none-any.whl |
|---|---|
| Size | 33.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3c982652681769ff367f21fab96790706ae32b06d4e2d5fc7ece5ea011147f04
|
|
BLAKE2b-256 checksum How to use checksums |
b4be7a052f48010d972575dcefc813f0a8d93902d95ea50d43b7c865246593fd
|
| 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 Nov 13, 2026.
Transparency logSecurity for postmarker 2.1
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.
Attestation for postmarker-2.1.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 Nov 13, 2026.
Transparency logA 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.