Skip to content

EmailWidget - Powerful Email Component Library

✨ Features

  • Lightweight & Compact: Quick installation with no complex dependencies (under 1MB)
  • Easy to Use: Clear and simple API, create beautiful email templates with just a few lines of code
  • Complete Documentation: Project has comprehensive documentation and type annotations for full IDE support
  • Rich Components: Currently includes 15+ beautiful display components, all following Fluent design, viewable below
  • Thoroughly Tested: Core functionality is completely tested to ensure project reliability
  • Completely Free: Project uses MIT open source license, you can use it freely in any commercial project

✨ Why Choose EmailWidget?

Want to send alerts or logs to email but don't know how to beautify them and they look ugly? Use EmailWidget to complete the last step of sending emails!

Want a beautiful email template but don't know HTML/CSS or just too lazy to write? Online templates are difficult to reuse after modification and don't support mobile? Then welcome to try EmailWidget - reusable, responsive, complete type hints, comprehensive documentation, lightweight email component library to help you quickly build your own report templates.

EmailWidget is an email component library designed specifically for Python developers, allowing you to create beautiful HTML email reports with just a few lines of code without needing to understand HTML and CSS details for emails. The project is verified by 1000+ test cases with 100% test coverage for core code, ensuring stability and reliability.

The email style below can be created with just 3 lines of code, and the generated content can be directly sent as email, recipients will also see beautiful emails.

Python
from email_widget import Email

email = Email("欢迎使用EmailWidget")

email.add_card("Python版本", "您需要Python3.10或以上才能使用EmailWidget", metadata={"Python版本": "3.10+"})

email.add_quote("EmailWidget是一个用于构建和发送HTML邮件的Python库。", "EmailWidget")

email.export_html('welcome_email.html')

image-20250706200253564

🚀 Quick Start

📦 Installation

Bash
pip install EmailWidget

Create Professional Reports in 30 Seconds

Python
from email_widget import Email, TextWidget, ProgressWidget
from email_widget.core.enums import TextType, ProgressTheme

# 创建邮件
email = Email("📊 业务报告")

# 添加标题
email.add_widget(
    TextWidget()
    .set_content("季度业绩总结")
    .set_type(TextType.TITLE_LARGE)
)

# 添加进度指标
email.add_widget(
    ProgressWidget()
    .set_value(92)
    .set_label("目标完成率")
    .set_theme(ProgressTheme.SUCCESS)
)

# 导出HTML
email.export_html("report.html")
📊 业务报告

🎪 Use Cases

Basic Components

Python
# 8种预设样式
email.add_widget(
    TextWidget()
    .set_content("大标题")
    .set_type(TextType.TITLE_LARGE)
)

email.add_widget(
    TextWidget()
    .set_content("章节标题")
    .set_type(TextType.SECTION_H2)
)

email.add_widget(
    TextWidget()
    .set_content("正文内容,支持多行文本和自动格式化。")
    .set_type(TextType.BODY)
)

image-20250702112724320

Python
# DataFrame直接导入
table = TableWidget().set_title("销售数据")
table.set_dataframe(df)

# 手动添加行
table = TableWidget()
table.set_headers(["产品", "销量", "状态"])
table.add_row(["iPhone", "1000", "success"])
table.add_row(["iPad", "800", "warning"])

email.add_widget(table)

image-20250702113233960

Python
# matplotlib图表
fig, ax = plt.subplots()
ax.plot([1, 2, 3, 4], [1, 4, 2, 3])
ax.set_title("趋势图")

email.add_widget(
    ChartWidget()
    .set_chart(plt)
    .set_title("数据趋势")
    .set_description("显示业务指标变化趋势")
)

image-20250702113423501

Advanced Components

Python
# 线性进度条
email.add_widget(
    ProgressWidget()
    .set_value(75)
    .set_label("项目进度")
    .set_theme(ProgressTheme.PRIMARY)
)

# 圆形进度条
email.add_widget(
    CircularProgressWidget()
    .set_value(85)
    .set_label("完成率")
)

image-20250702113553794

Python
# 状态卡片
email.add_widget(
    CardWidget()
    .set_title("系统状态")
    .set_content("所有服务正常运行")
    .set_icon("✅")
)

# 状态列表
status_items = [
    {"label": "数据库", "status": "success", "value": "连接稳定"},
    {"label": "API", "status": "warning", "value": "响应时间较长"}
]
email.add_status_items(status_items)

image-20250702113934973

Python
# 警告框
email.add_widget(
    AlertWidget()
    .set_content("系统维护通知")
    .set_alert_type(AlertType.WARNING)
    .set_title("重要提醒")
)

# 引用样式
email.add_widget(
    QuoteWidget()
    .set_content("数据是新时代的石油")
    .set_author("Clive Humby")
    .set_source("数据科学家")
)

image-20250702114027153

📖 Documentation Navigation

🤝 Community & Support

Getting Help

Contributing

We recommend using uv as the package management tool for project management and development

Bash
# 1. Clone project
git clone https://github.com/271374667/EmailWidget.git

# 2. Install development environment
uv sync

# 3. Run tests
uv run pytest

# 4. Submit changes
git commit -m "Feature: Add new functionality"

Social Media

📄 License

This project uses the MIT License open source license.


⭐ **If this project helps you, please give us a star!** ⭐

Made with ❤️ by Python调包侠

📺 Watch Video Tutorials📖 View Complete Documentation