Skip to main content

postmark-python

Python Versions License: MIT Tests
Postmark Python SDK

The official (Beta) Python SDK for Postmark — send emails, manage bounces, templates, webhooks, and more.

For tutorials and detailed usage, check out the wiki.

For details about the Postmark API in general, see the Postmark developer docs.

Requirements

  • Python 3.10+

Installation

Install from PyPI as postmark-python (the Python package you import is still postmark):

pip install postmark-python

Quick Start

The SDK is async-first — all API calls return awaitables. As of v0.3.0, a synchronous wrapper is also available for use in non-async contexts.

Async:

import asyncio
import os

import postmark

# Tokens are read from the environment here. Optionally: pip install python-dotenv,
# then use load_dotenv() to populate os.environ from a .env file.


async def main():
    async with postmark.ServerClient(os.environ["POSTMARK_SERVER_TOKEN"]) as client:
        response = await client.outbound.send(
            {
                "sender": "sender@example.com",
                "to": "recipient@example.com",
                "subject": "Hello from Postmark",
                "text_body": "Sent with the Postmark Python SDK.",
            }
        )
        print(f"Sent: {response.message_id}")


asyncio.run(main())

Sync (v0.3.0+):

import os

import postmark.sync

with postmark.sync.ServerClient(os.environ["POSTMARK_SERVER_TOKEN"]) as client:
    response = client.outbound.send(
        {
            "sender": "sender@example.com",
            "to": "recipient@example.com",
            "subject": "Hello from Postmark",
            "text_body": "Sent with the Postmark Python SDK.",
        }
    )
    print(f"Sent: {response.message_id}")

Why sender, not from? from is a reserved keyword in Python, so the SDK uses sender for the sending address. Everything else matches the Postmark API field names directly.

Two Client Types

Client Token Use for
ServerClient Server API token Sending email, bounces, templates, stats, webhooks, streams
AccountClient Account API token Domains, sender signatures, managing servers, data removals
import postmark

# Use as async context managers to ensure connections are closed
async with postmark.ServerClient(os.environ["POSTMARK_SERVER_TOKEN"]) as client:
    ...

async with postmark.AccountClient(os.environ["POSTMARK_ACCOUNT_TOKEN"]) as account:
    ...

# Or call close() explicitly when done
client = postmark.ServerClient(os.environ["POSTMARK_SERVER_TOKEN"])
await client.close()

Django

postmark.django.EmailBackend is a drop-in EMAIL_BACKEND for Django's django.core.mail, supporting Django 4.2 LTS through 6.1. Requires the django extra:

pip install postmark-python[django]
# settings.py
EMAIL_BACKEND = "postmark.django.EmailBackend"
POSTMARK_SERVER_TOKEN = "your-server-token"

See the Django Backend wiki page and examples/django/ for tags, metadata, attachments, and signals.

Development

git clone https://github.com/ActiveCampaign/postmark-python.git
cd postmark-python
poetry install
poetry run pre-commit install
# Run tests
poetry run pytest

# Lint and type-check
poetry run pre-commit run --all-files

Contributing

See CONTRIBUTING.md for setup, testing, and PR guidelines.

Support

License

MIT — see LICENSE.

Download files

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

Source Distribution

postmark_python-0.4.0.tar.gz (35.9 kB view details)

Uploaded Source

Built Distribution

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

postmark_python-0.4.0-py3-none-any.whl (59.4 kB view details)

Uploaded Python 3

File details

Details for the file postmark_python-0.4.0.tar.gz.

File metadata

  • Download URL: postmark_python-0.4.0.tar.gz
  • Upload date:
  • Size: 35.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for postmark_python-0.4.0.tar.gz
Algorithm Hash digest
SHA256 208a6e37ddd9e1d4b6527c4cb862f662087f78c252da769f2a24131a7d19ade3
MD5 de080979a8d1efa6352d894f41dc4fdf
BLAKE2b-256 394cbd0e3cb1b649eee85c180695e84381d1940986b2c2439d8bb975d37a8ba9

See more details on using hashes here.

Provenance

The following attestation bundles were made for postmark_python-0.4.0.tar.gz:

Publisher: publish.yml on ActiveCampaign/postmark-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file postmark_python-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: postmark_python-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 59.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for postmark_python-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cf5ba3aee77af58535943e5971659126e819660d53d0062d240ada56fdadf2f2
MD5 8a5821af5fcf08c4cd760c875cc94e29
BLAKE2b-256 c27f2b7f46c289035e13a80fe4741bdbf47af8ea38d0a81c09b0f5de4d0e41d9

See more details on using hashes here.

Provenance

The following attestation bundles were made for postmark_python-0.4.0-py3-none-any.whl:

Publisher: publish.yml on ActiveCampaign/postmark-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

Image AWS Cloud computing and Security Sponsor Image Datadog Monitoring Image Depot Continuous Integration Image Fastly CDN Image Google Download Analytics Image Sentry Error logging Image StatusPage Status page