PrettyTable helps Python programs print tabular data as readable ASCII tables. You can build tables row by row, in bulk, or from CSV and database cursors.
Overview
PrettyTable is a Python package for turning rows and columns of data into fixed-width ASCII tables suited to terminals, logs, and simple reports. You define field names, add rows or columns through several APIs, and render the result to stdout or as a string.
Data can enter the table in flexible ways. Individual rows go in one at a time, whole lists can be added at once, or columns can be filled separately. The library can read comma-separated files and populate a table from a DB-API cursor, which is useful when listing query results in a shell-oriented layout.
Output control covers printing, string export, and alternate layouts. The getstring method produces the same text as print would; getformattedstring can target other formats when supported. Pagination splits large tables across pages with configurable page length and separators.
Presentation options include column alignment for all columns or per field, sorting by a field with optional reverse order, row filtering via callables, restricting visible fields or row ranges, section dividers, titles including multiline titles, and preset or custom visual styles such as Markdown, plain columns, or box-drawing borders.
Key features
- Row, batch, and column-oriented table building
- Import from CSV and DB-API cursors
- ASCII print and string output
- Multiple output formats via formatting API
- Pagination for large tables
- Column alignment and sorting
- Row filtering and partial display
- Built-in and customizable table styles
Use cases
- CLI tools showing query or report results
- Logging structured rows in development
- Quick terminal reports from Python scripts
- Exporting small datasets as readable text
- Prototyping tabular output before GUI work