New to the Lettr Python SDK? Start with the Python Quickstart to learn the basics, then return here for Flask-specific integration patterns.
Prerequisites
Before you begin, make sure you have:API Key
Create an API key in the Lettr dashboard
Verified Domain
Add and verify your sending domain
- Python 3.8 or later installed
- Flask web framework
- A verified sending domain in your Lettr dashboard
Quick Setup
Get started in three quick steps: install dependencies, configure Flask, and send.Install dependencies
Flask Application Structure
For production applications, organize your code with a proper structure:Configuration
Create aconfig.py file for application configuration:
Email Service
Create an email service inservices/email.py:
Application Factory
Create an application factory inapp.py:
Routes
Create authentication routes inroutes/auth.py:
Advanced Features
Using Templates
Send emails using Lettr-managed templates:Background Task Queue with Celery
For production applications, send emails asynchronously using Celery:tasks.py:
Error Handling
Implement error handling in your routes:See Error Handling in the Python Quickstart for comprehensive error handling patterns.
Testing
Create unit tests for your email service using Flask’s test client:Best Practices
Use Flask Configuration
Store email settings in Flask configuration:Logging
Use Flask’s built-in logger:Rate Limiting
Use Flask-Limiter to prevent abuse:What’s Next
Python SDK
Complete Python SDK documentation
FastAPI Integration
Use Lettr with FastAPI
API Reference
Complete API documentation
Templates
Use Lettr-managed templates