A Python library for generating beautiful HTML emails
Project description
Mayil
A Streamlit-like package for creating structured and formatted emails in Python.
Installation
pip install mayil
Usage
import mayil as my
# Add components to your email
my.header("Welcome to Our Newsletter")
my.text("This is a sample text paragraph.")
my.text("This is another paragraph.")
# Get the complete HTML body
html_content = my.body()
Components
Header
my.header("Your Header Text")
Text
my.text("Your paragraph text")
Formatted Table (ftable)
import pandas as pd
# Create a sample dataframe
df = pd.DataFrame({
'Score': [85, 92, 78],
'Status': ['Active', 'Inactive', 'Active'],
'Date': pd.to_datetime(['2024-01-01', '2024-01-02', '2024-01-03'])
})
# Define conditions for formatting
conditions = {
'Score': [
(lambda x: x < 90, '#ff0000'), # Red if < 90
(lambda x: x >= 90, '#00ff00') # Green if >= 90
],
'Status': [
(lambda x: x == 'Active', '#00ff00'), # Green if active
(lambda x: x == 'Inactive', '#ff0000') # Red if inactive
],
'Date': [
(lambda x: x < pd.Timestamp('2024-01-02'), '#ff0000'), # Red if before Jan 2
(lambda x: x >= pd.Timestamp('2024-01-02'), '#00ff00') # Green if Jan 2 or later
]
}
# Apply formatting
my.ftable(df, conditions=conditions) # Apply to both cell and text
my.ftable(df, cell_colors=conditions) # Apply only to cell background
my.ftable(df, text_colors=conditions) # Apply only to text
Features
- Streamlit-like interface for building emails
- HTML-based output
- Styled components
- Chainable methods
- Conditional formatting for tables
- Support for various data types (numbers, strings, dates)
- Flexible color customization
Advanced Usage
Creating Multiple Instances
While the default instance is available through import mayil as my, you can create additional instances if needed:
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)
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.0.tar.gz.
File metadata
- Download URL: mayil-0.2.0.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1cbe72dc243738cc6d5fc620a36e0353132e6987236c5681e4d13d52c6183708
|
|
| MD5 |
10099f0e4439b1b3bd6d7a8bde0ddcd5
|
|
| BLAKE2b-256 |
f69888e66ac5695ca0764e09939fc80763f2726aec5b077d48b3d56e3799b59e
|
File details
Details for the file mayil-0.2.0-py3-none-any.whl.
File metadata
- Download URL: mayil-0.2.0-py3-none-any.whl
- Upload date:
- Size: 7.9 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 |
c4b3e06d9ab25879312e4d16214f17bd95311f577675e51b12fc07cc4a3d0f81
|
|
| MD5 |
b95fab0b31aeaa6a22f4492c1c2f66ca
|
|
| BLAKE2b-256 |
24d472e123a9608897eb84f2d79ad737b0996b13b56c2a041f065ab9e087af33
|