Skip to main content

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:

  1. conditions: Applies formatting to both cell background and text
  2. cell_colors: Applies formatting only to cell background
  3. text_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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mayil-0.2.1.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mayil-0.2.1-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file mayil-0.2.1.tar.gz.

File metadata

  • Download URL: mayil-0.2.1.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

Hashes for mayil-0.2.1.tar.gz
Algorithm Hash digest
SHA256 a7ab1277d261fb96ff34eb12d1d5ccf29d6044188d85203420ad6710cf98fdd6
MD5 f3df12b7afcf40900916731497f75185
BLAKE2b-256 189d978db7bea64a33c4ab79acf77a057e371f32014d70edb893721a977d1b2a

See more details on using hashes here.

File details

Details for the file mayil-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: mayil-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.4

File hashes

Hashes for mayil-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5509a5bc664be44f9ecf5455bb1a4bcc77e20d9f5d7a3bc496f348528bdae84c
MD5 371a798abd7b9086f376037fe7b87950
BLAKE2b-256 685b41e09a4c94cde73ea97ab40d3faaa019851f273c6f2162a54c9933de1b19

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page