Registry / data / pretty-html-table

pretty-html-table

JSON →
library0.9.16pypypi✓ verified 25d ago

pretty-html-table (v0.9.16) is a Python library designed to convert pandas DataFrames into aesthetically pleasing HTML tables, primarily for use in email reports. It offers 12 different color themes and formats HTML at the DataFrame row level to ensure broad compatibility across various email providers, avoiding common CSS rendering issues. The library is currently in maintenance mode with infrequent releases, with the last significant update in April 2022.

pip install pretty-html-table
INSTALL
IMPORT
SIG · PRETTY-HTML-TABLE
P
pretty-html-table
datapythonv0.9.16
Install
7.6s avg
Import
Disk
164MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.9.16 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 164.6MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 7.6s · import 0.000s · 157MB
164MB installed
● package 164MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

build_table
from pretty_html_table import build_table

This quickstart demonstrates how to create a pandas DataFrame and then convert it into a styled HTML table using `build_table`. The resulting HTML string can be printed, saved to a file, or embedded directly into an email body.

import pandas as pd from pretty_html_table import build_table # Create a sample pandas DataFrame data = { 'Name': ['Alice', 'Bob', 'Charlie'], 'Age': [24, 27, 22], 'City': ['New York', 'Los Angeles', 'Chicago'] } df = pd.DataFrame(data) # Convert the DataFrame to a pretty HTML table with a 'blue_light' theme html_table = build_table(df, 'blue_light', width='auto', font_size='medium', text_align='left') # Print the HTML table (for demonstration) print(html_table) # Optionally, save to an HTML file # with open('pretty_table.html', 'w') as f: # f.write(html_table) # print("HTML table saved to pretty_table.html")
Debug
Known issues
gotchaWhen embedding the generated HTML into emails, ensure you use the `HTMLBody` property (e.g., `mail.HTMLBody` for Outlook objects) rather than `Body` to correctly render the table. Using `Body` will typically display the raw HTML text.
fix
Refer to your email client's API documentation for the correct property to send HTML content. For many Python email libraries, ensure the `Content-Type` header is set to `text/html`.
affects: All versions
gotchaThe library prioritizes compatibility with email clients by applying styles at the HTML table row level, rather than relying heavily on external CSS. This approach ensures consistent rendering across many email services but means advanced CSS customizations or responsive design patterns typically used for web pages might not be directly supported or effective.
fix
For complex web-based table designs requiring full CSS control or responsiveness, consider other libraries or direct CSS implementations. pretty-html-table is optimized for email embeddability.
affects: All versions
gotchaWhen using the `width_dict` argument to set custom column widths, the provided list of width strings (e.g., `['100px', 'auto', '300px']`) must have a length exactly matching the number of columns in your pandas DataFrame. An incorrect length will lead to unexpected or unapplied width styles.
fix
Verify that `len(width_dict)` is equal to `len(df.columns)` before passing it to `build_table`.
affects: All versions
gotchaThe library appears to be in maintenance mode. The last PyPI release (v0.9.16) was in April 2022, and the GitHub repository shows the last significant commit approximately four years prior. While functional, active development for new features or rapid bug fixes may be limited.
fix
Evaluate the current functionality against your needs. For long-term projects requiring active support or cutting-edge features, consider the maintenance status when making your choice.
affects: 0.9.16 and potentially future versions if maintenance continues at this pace
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pretty_html_table'
The `pretty-html-table` package is not installed in your Python environment or there is a typo in the import statement.
fix
Install the package using pip: `pip install pretty-html_table`
pretty_html_table returning HTML text rather than table
The HTML output from `pretty_html_table.build_table` is being inserted into an email client's plain text body instead of its HTML body, causing it to render as raw HTML text.
fix
Ensure you are assigning the output to the email client's HTML body property, such as `mail.HTMLBody` when sending emails.
AttributeError: module 'pretty_html_table' has no attribute 'PrettyTable'
You are attempting to import or access a class named 'PrettyTable' from the `pretty_html_table` module, but the primary function for creating tables in this library is `build_table`, and there is no 'PrettyTable' class. This often happens when confusing it with the `prettytable` library.
fix
Import the correct function: `from pretty_html_table import build_table` and use `build_table()` instead of trying to instantiate `PrettyTable()`.
Upgrade
Version history
0.9.16latest on PyPI · released Apr 25, 2022
Audit
Dependencies
pandasrequiredThe library's core functionality is to convert pandas DataFrames to HTML tables.
Agent activity
11 hits · last 30 days
node
8
OpenAI (training)
1
Resources
pretty-html-table — pip install pretty-html-table · libregistry