A minimal Python client for the Postmark API
Project description
Postie
A minimal Python client for the Postmark API.
Installation
pip install postie
Quick Start
from postie import PostieClient
# Initialize client
client = PostieClient(server_token="your-postmark-server-token")
# Send a simple email
response = client.send_email(
from_email="support@nomadicinfluence.com",
to="user@example.com",
subject="Hello from Postie",
html_body="<h1>Hello!</h1><p>This is a test email.</p>",
text_body="Hello! This is a test email."
)
print(response)
Features
- ✅ Send single emails
- ✅ Send batch emails (up to 500)
- ✅ Send template-based emails
- ✅ HTML and plain text support
- ✅ CC, BCC, Reply-To
- ✅ Email tagging and metadata
- ✅ Open and link tracking
- ✅ Type hints
- ✅ Minimal dependencies (only
requests)
Usage
Send Email
client.send_email(
from_email="support@nomadicinfluence.com",
to="user@example.com",
subject="Welcome!",
html_body="<h1>Welcome to our platform</h1>",
text_body="Welcome to our platform",
tag="onboarding",
track_opens=True
)
Send Batch Emails
emails = [
{
"From": "support@nomadicinfluence.com",
"To": "user1@example.com",
"Subject": "Hello User 1",
"HtmlBody": "<p>Hello User 1</p>"
},
{
"From": "support@nomadicinfluence.com",
"To": "user2@example.com",
"Subject": "Hello User 2",
"HtmlBody": "<p>Hello User 2</p>"
}
]
responses = client.send_batch(emails)
Send Template Email
client.send_template_email(
from_email="support@nomadicinfluence.com",
to="user@example.com",
template_id=123456,
template_model={
"name": "John Doe",
"action_url": "https://example.com/verify"
}
)
Django Integration
Option 1: Use Django Email Backend (Recommended)
Configure Postie as your Django email backend:
# settings.py
EMAIL_BACKEND = 'postie.django_backend.PostieEmailBackend'
POSTMARK_SERVER_TOKEN = os.getenv('POSTMARK_SERVER_TOKEN')
DEFAULT_FROM_EMAIL = 'support@nomadicinfluence.com'
Then use Django's standard email functions:
from django.core.mail import send_mail, EmailMultiAlternatives
# Simple email
send_mail(
subject='Welcome!',
message='Welcome to our platform',
from_email='support@nomadicinfluence.com',
recipient_list=['user@example.com'],
)
# HTML email
email = EmailMultiAlternatives(
subject='Welcome!',
body='Welcome to our platform',
from_email='support@nomadicinfluence.com',
to=['user@example.com'],
)
email.attach_alternative('<h1>Welcome!</h1>', "text/html")
email.send()
Option 2: Use PostieClient Directly
# utils/email.py
from postie import PostieClient
from django.conf import settings
postmark = PostieClient(server_token=settings.POSTMARK_SERVER_TOKEN)
def send_welcome_email(user_email, user_name):
postmark.send_email(
from_email="support@nomadicinfluence.com",
to=user_email,
subject=f"Welcome {user_name}!",
html_body=f"<h1>Welcome {user_name}!</h1>",
text_body=f"Welcome {user_name}!"
)
Error Handling
from postie import PostieClient, PostieAPIError, PostieError
try:
client.send_email(...)
except PostieAPIError as e:
print(f"API Error: {e}")
print(f"Error Code: {e.error_code}")
print(f"Status Code: {e.status_code}")
except PostieError as e:
print(f"Client Error: {e}")
Requirements
- Python 3.7+
- requests
License
MIT
Contributing
Contributions welcome! Please open an issue or PR.
Links
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
postiee-0.1.0.tar.gz
(5.9 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file postiee-0.1.0.tar.gz.
File metadata
- Download URL: postiee-0.1.0.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.0 CPython/3.14.2 Darwin/25.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
89d8437a3ccf2d725443ff4cc9ffcc5ef0ff23e2959e7c8890dcdb9147a5025c
|
|
| MD5 |
de30b29339aacf8f5dcf4957ad7feda7
|
|
| BLAKE2b-256 |
bf4496d770a0e0caa68964c92e1f17b4cd5bf4ce82e731889d6c4cfe2015de66
|
File details
Details for the file postiee-0.1.0-py3-none-any.whl.
File metadata
- Download URL: postiee-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.0 CPython/3.14.2 Darwin/25.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
28a5efc15f76bffd1f2532269e30a70828b650be22a4dfc94b66e7b4d05a130d
|
|
| MD5 |
4fb76fbd40b151654bf63b664e43787d
|
|
| BLAKE2b-256 |
784e31890638b227855066e1589e6bec244099d8ad3404bb61ee2a341d18890c
|