prettytable

Display tabular data in visually appealing ASCII tables in Python

Library
PyPI
v3.18.0
1,670stars
BSD 3-Clause License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
76/100Good
Development Activity64
Maintenance64
Community76
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
83/100Excellent
Architecture82
Code Quality84
Innovation74
Learning Curve92

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.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search