A Python library for generating beautiful HTML emails
Project description
Mayil
A beautiful HTML email generator for Python that makes creating professional, responsive emails a breeze.
Installation
pip install mayil
Quick Start
import mayil as my
import pandas as pd
# Add content
my.title("Welcome to Our Newsletter", center=True)
my.header("Latest Updates")
my.text("Stay informed with our latest news and updates.")
my.metric("Active Users", "1,234", color="#88C0D0")
my.sticky_note("Important Notice", "Please read this carefully.", color="blue")
# Add a table
df = pd.DataFrame({
'Name': ['John', 'Jane'],
'Score': ['95', '85']
})
my.dataframe(df, align='center')
# Get the HTML content
html_content = my.body
Features
- 🎨 Beautiful, responsive email templates
- 📊 Data visualization with tables and metrics
- 🎯 Conditional formatting for tables
- 📝 Rich text formatting
- 📱 Mobile-friendly design
- 🔗 Easy hyperlink support
- 📐 Flexible layout options with columns
- 📈 Interactive Plotly charts support
API Reference
Basic Components
Title
my.title("Welcome", center=True)
Adds a large title to the email. Optionally center it.
Header
my.header("Section Title")
Adds a section header.
Subheader
my.subheader("Subsection Title")
Adds a subsection header.
Text
my.text("Your paragraph text", justify=True)
Adds a paragraph of text. Optionally justify the text.
Metric
my.metric("Active Users", "1,234", color="#88C0D0")
Displays a metric with label and value. Customize the value color.
Sticky Note
my.sticky_note("Important", "Read this carefully", color="blue")
Adds a sticky note component. Colors: yellow, green, blue, red, white, violet, orange, darkgreen.
Divider
my.divider()
Adds a light grey dotted divider line.
Layout Components
Columns
cols = my.columns(3)
with cols[0]:
my.metric("Metric 1", "100")
with cols[1]:
my.metric("Metric 2", "200")
Creates a multi-column layout (max 4 columns).
Table Components
DataFrame
df = pd.DataFrame({
'Name': ['John', 'Jane'],
'Score': ['95', '85']
})
my.dataframe(df, align='center')
Adds a styled DataFrame to the email.
Formatted Table (ftable)
conditions = {
'Score': [
(lambda x: x < '90', '#ffb3ba'), # Pastel red
(lambda x: x >= '90', '#baffc9') # Pastel green
],
'Status': [
(lambda x: x.lower() == 'active', '#bae1ff'), # Pastel blue
(lambda x: x.lower() == 'inactive', '#ffdfba') # Pastel orange
]
}
my.ftable(df, cell_colors=conditions, align='center')
Adds a table with conditional formatting based on column values.
Data Visualization
Plotly Chart
import plotly.express as px
# Create a sample plotly figure
df = pd.DataFrame({
'Date': pd.date_range('2024-01-01', '2024-01-10'),
'Value': [10, 15, 13, 17, 19, 16, 14, 18, 20, 22]
})
fig = px.line(df, x='Date', y='Value', title='Trend Analysis')
# Add the plotly chart to the email
my.plotly_chart(fig)
Adds an interactive Plotly chart to the email. The chart will be rendered as an HTML component that can be interacted with in email clients that support HTML content.
Links
Hyperlink
my.hyperlink("Visit our website", "https://example.com")
Adds a clickable link to the email.
Advanced Usage
Creating Multiple Instances
from mayil import Mayil
# Create a new instance
custom_instance = Mayil()
custom_instance.header("Custom Header")
Table Formatting Options
The ftable method supports three types of conditional formatting:
conditions: Applies formatting to both cell background and textcell_colors: Applies formatting only to cell backgroundtext_colors: Applies formatting only to text
Each condition is defined as a tuple of (lambda function, color) where:
- The lambda function should return a boolean
- The color can be any valid CSS color (hex, rgb, named colors)
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
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
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 mayil-0.2.2.tar.gz.
File metadata
- Download URL: mayil-0.2.2.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
250e4303decaeb9531a5a3a96e0ec83eb049c18471e38a47f6bc18cc8486aa88
|
|
| MD5 |
5f6388afe60ab544e080392976977f7c
|
|
| BLAKE2b-256 |
8150464c3d8d8527bf8a851e2036b28963f7e42c90e47d2766e937097d2f172c
|
File details
Details for the file mayil-0.2.2-py3-none-any.whl.
File metadata
- Download URL: mayil-0.2.2-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
181073e2f47c67a15aedb72da0221b78c66f20402fd04e1cd40376edf1d8e484
|
|
| MD5 |
7088d148ce08de8b395aad210ba0db5a
|
|
| BLAKE2b-256 |
830d205ecd988eb1bcb72f8d4a968c36b6c519a946404281edc9946582988835
|