Send transactional emails from Python with the type-safe lettr SDK, featuring sync and async clients, type hints, and typed error handling.
Send transactional emails from your Python applications using the official Lettr Python SDK. The SDK provides a type-safe, intuitive interface for the Lettr API with full async support and comprehensive error handling.The lettr package gives you a Pythonic API client that works with any Python application — Django, Flask, FastAPI, or standalone scripts. It follows Python conventions and integrates seamlessly with your existing codebase.Using Cursor? Jump straight in using this prompt
Get started in three quick steps: install, configure, and send.
1
Install the SDK
pip install lettr
The SDK requires Python 3.8+ and automatically installs httpx as a dependency. For async support, httpx’s async features are included by default.
2
Create a client
import lettrclient = lettr.Lettr("your-api-key")# Verify the client is configured correctlyauth = client.auth_check()print(f"Connected to Lettr (Team ID: {auth.team_id})")
Store your API key in environment variables, never hardcode it. API keys use the lttr_ prefix followed by 64 hexadecimal characters.
3
Send your first email
response = client.emails.send( from_email="sender@yourdomain.com", to=["recipient@example.com"], subject="Hello from Lettr", html="<h1>Hello!</h1><p>This is a test email.</p>",)print(f"Email sent! Request ID: {response.request_id}")print(f"Accepted: {response.accepted}")
The response includes a request_id for tracking and the number of accepted recipients.
The sender domain must be verified in your Lettr dashboard before you can send emails. Sending from an unverified domain returns a validation error.
response = client.emails.send( from_email="notifications@yourdomain.com", to=["user@example.com"], subject="Plain text email", text="This is a plain text email.\n\nIt has no HTML formatting.",)
Send both HTML and plain text versions for maximum compatibility:
response = client.emails.send( from_email="notifications@yourdomain.com", to=["user@example.com"], subject="Multipart email", html="<h1>Hello!</h1><p>This is the HTML version.</p>", text="Hello!\n\nThis is the plain text version.",)
Providing both HTML and plain text ensures your emails are readable in all email clients, including text-only clients and accessibility tools.