prettytable
Display tabular data in visually appealing ASCII tables in Python
Repository Health
Technical Analysis
PrettyTable is a Python library for displaying tabular data in visually appealing ASCII tables. You build a table by adding rows, columns, or importing from CSV, HTML, or database cursors, then render it as neatly aligned text with borders, headers, and configurable styling. It is one of the most popular ways to present structured data in terminal output, logs, and command-line tools.
Beyond plain ASCII, PrettyTable supports sorting, filtering, and slicing of rows, per-column alignment and formatting, custom border characters and preset styles, and alternative output formats including HTML, JSON, and Markdown-friendly text. A companion ColorTable class adds ANSI color themes for richer terminal presentation.
What You Get
- A PrettyTable object that renders rows and columns as aligned ASCII tables
- Multiple ways to load data: add_row, add_column, and importers for CSV, HTML, and cursors
- Sorting, filtering, and row/column slicing when producing output
- Per-column alignment, formatting, and configurable borders and preset styles
- Alternative output formats including HTML and JSON, plus colored output via ColorTable
Common Use Cases
- Formatting command-line tool output into readable tables
- Presenting query results or reports in terminal and log output
- Rendering the same dataset as ASCII, HTML, or JSON from one table
- Building quick, human-readable summaries in scripts and notebooks
Under The Hood
Architecture - The library is small and focused: src/prettytable/prettytable.py contains the core PrettyTable class, which stores rows and field names and computes column widths, alignment, and borders at render time. colortable.py subclasses it to inject ANSI color themes, main.py provides the runnable demo (python3 -m prettytable), and init.py exports the public names. Output styling is driven by a set of options (borders, padding, alignment, sort key, preset style) resolved when the table is stringified into ASCII, HTML, or JSON.
Tech Stack - Pure Python with no required runtime dependencies, packaged via a modern pyproject.toml build. It ships a py.typed marker for full type-hint support, uses Black for formatting, and is tested across supported Python 3 versions through tox and GitHub Actions.
Code Quality - The project is well maintained and type-annotated, with a tests directory, Codecov coverage reporting, mypy checking (requirements-mypy.txt), and CI on every change. Its long history (since 2009) and stable API make it a dependable, battle-tested utility, and it is covered by a Tidelift subscription for enterprise support.
API Design - The API is intuitive and discoverable: create a PrettyTable, call add_row or add_column, set attributes like align, sortby, and field_names, then print the table or call get_string, get_html_string, or get_json_string. The README doubles as a thorough tutorial and the built-in demo shows output instantly, giving the library a very gentle learning curve.
Used by 2 apps in this directory
Keep
Devops · Automation · Monitoring
The open-source AIOps and alert management platform that unifies 130+ monitoring tools into a single pane of glass with AI-powered correlation, deduplication, and workflow automation.
TDengine
Databases
A high-performance, open-source time-series database built in C for IoT, connected vehicles, and industrial monitoring workloads, with built-in stream processing, caching, and data subscription.