|
|
|
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.
- Python 3.10+
Install from PyPI as postmark-python (the Python package you import is still postmark):
pip install postmark-pythonThe SDK is fully async. All API calls must be awaited.
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())| 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()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- Fork the repository
- Create a feature branch
- Add tests for your changes
- Ensure all checks pass (
poetry run pre-commit run --all-files) - Open a Pull Request
- Issues: GitHub Issues
- Postmark Support: support@postmarkapp.com
MIT — see LICENSE.
