Introduction
Python Mailable is an email builder for Python, inspired by Laravel’s Mailable class. It provides a clean and reusable structure for defining, composing, and rendering emails with rich context and templates.
from dataclasses import dataclassfrom python_mailable.mailable import Mailable
@dataclassclass OrderShipped(Mailable): user: User
def build(self): return ( self.to(self.user.email) .subject("Your order has shipped!") .template("emails/order_shipped.html.j2") .with_context({"user": self.user}) )Why Python Mailable?
Section titled “Why Python Mailable?”Mixing string templates, recipients, and attachments directly into your sending code makes emails hard to test and hard to reuse. Python Mailable gives each email its own class with a single build() method, so the structure of an email is defined once and rendered the same way everywhere.
Features
Section titled “Features”- Define email classes with subjects, recipients, and templates
- Render HTML and plain-text versions from separate Jinja2 templates
- Pass context to templates for dynamic rendering
- Attach files easily
- Designed for clarity, testability, and reusability