Python SDK
Use your favorite mail provider Zupost, seamless with our Python SDK.
Type Hints
Full PEP 484 annotations with py.typed marker
Dataclasses
Typed response models for IDE autocomplete
There are many various ways of sending emails with Zupost. It can be a template, created in our no-code-editor. HTML or just markdown. No matter what you prefer, Zupost has it for you. And if you encounter issues with the documentation or the SDK, don't hesitate to open a Issue.
Installation
pip install zupostSetting Up
After successfully installing Zupost to your project, you can start by creating a Zupost instance.
from zupost import Zupost
zupost = Zupost("your-api-key")Sending Emails
You can send emails in various ways, see some usage examples:
from zupost import Zupost, SendEmailOptions
zupost = Zupost("your-api-key")
# Send with HTML content
response = zupost.emails.send(SendEmailOptions(
from_address="sender@example.com",
to="recipient@example.com",
subject="Hello World",
html="<h1>Hello!</h1>",
))
print(f"Email sent: {response.id}")
# Send to multiple recipients
zupost.emails.send(SendEmailOptions(
from_address="sender@example.com",
to=["user1@example.com", "user2@example.com"],
subject="Team Update",
markdown="# Hello Team\n\nThis is a **markdown** email.",
))
# Send with a template
zupost.emails.send(SendEmailOptions(
from_address="sender@example.com",
to="recipient@example.com",
subject="Welcome!",
template_id="welcome-template",
variables={"name": "John"},
))With Attachments
You can attach files to your emails by providing them as base64-encoded strings.
import base64
from zupost import Zupost, SendEmailOptions, Attachment
zupost = Zupost("your-api-key")
with open("/path/to/invoice.pdf", "rb") as f:
content = base64.b64encode(f.read()).decode("utf-8")
zupost.emails.send(SendEmailOptions(
from_address="sender@example.com",
to="recipient@example.com",
subject="Invoice",
html="<p>Please find the invoice attached.</p>",
attachments=[
Attachment(filename="invoice.pdf", content=content),
],
))Using Context Manager
The SDK supports context manager for proper resource cleanup:
from zupost import Zupost, SendEmailOptions
with Zupost("your-api-key") as zupost:
response = zupost.emails.send(SendEmailOptions(
from_address="sender@example.com",
to="recipient@example.com",
subject="Hello World",
html="<h1>Hello!</h1>",
))
print(f"Email sent: {response.id}")Error Handling
from zupost import Zupost, SendEmailOptions, ApiException, ValidationException
zupost = Zupost("your-api-key")
try:
response = zupost.emails.send(SendEmailOptions(
from_address="sender@example.com",
to="recipient@example.com",
subject="Hello World",
html="<h1>Hello!</h1>",
))
except ValidationException as e:
print(f"Validation error: {e.message}")
except ApiException as e:
print(f"API error: {e.message} (status: {e.status_code})")Contribute on GitHub
Found an issue or want to contribute? Check out the repository for this project. We welcome contributions of all kinds!
Python SDK