Registry / serialization / prettytable

prettytable

JSON →
library3.18.0pypypi✓ verified 10d ago

PrettyTable is a Python library for easily displaying tabular data in a visually appealing ASCII table format. It supports various output formats including ASCII, HTML, CSV, JSON, LaTeX, and MediaWiki. The library is actively maintained with regular releases, currently at version 3.17.0.

pip install prettytable
INSTALL
IMPORT
SIG · PRETTYTABLE
P
prettytable
serializationpythonv3.18.0
Install
1.8s avg
Import
18ms
Disk
21MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.18.0 · 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.020s · 25.1MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.8s · import 0.016s · 26MB
21MB installed
● package 21MB
Code
Verified usage

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

PrettyTable
from prettytable import PrettyTable
ColorTable
from prettytable.colortable import ColorTable
Use ColorTable for ANSI color support.
TableStyle
from prettytable import TableStyle
Also HRuleStyle, VRuleStyle for granular styling enums.

Initialize a PrettyTable, define column headers using `field_names`, add data row by row with `add_row`, and then print the table. Customization for alignment and built-in styles is also demonstrated.

from prettytable import PrettyTable table = PrettyTable() table.field_names = ["City name", "Area", "Population"] table.add_row(["Adelaide", 1295, 1158259]) table.add_row(["Brisbane", 5905, 1857594]) table.add_row(["Sydney", 2058, 4336374]) print(table) # Example with alignment and style table.align["City name"] = "l" table.align["Population"] = "r" # To use custom styles, import TableStyle from prettytable import TableStyle table.set_style(TableStyle.MARKDOWN) print(table)
Debug
Known issues
breakingPrettyTable 3.17.0 dropped support for Python 3.9. Users on Python 3.9 or older should use an earlier version of PrettyTable (e.g., 3.16.0 or below) or upgrade their Python interpreter.
fix
Upgrade Python to 3.10+ or pin `prettytable<3.17.0`.
affects: >=3.17.0
deprecatedThe direct constants `hrule` and `tableStyle` were deprecated in version 3.12.0. Use the corresponding enum values from `HRuleStyle`, `VRuleStyle`, and `TableStyle` instead for clarity and type safety.
fix
Replace `prettytable.FRAME` with `HRuleStyle.FRAME` or `TableStyle.DEFAULT` etc. as appropriate.
affects: >=3.12.0
gotcha`ModuleNotFoundError: No module named 'prettytable'` is a common issue, often caused by installing `prettytable` in a different Python environment (e.g., virtual environment) than the one your IDE or script is using.
fix
Ensure `pip install prettytable` is run in the *same* Python environment where your script is executed. Verify the active Python interpreter in your IDE.
affects: All versions
gotchaPrior to 3.15.1, `add_rows()` could raise an `IndexError` if provided with an empty list that was not handled gracefully.
fix
Upgrade to `prettytable>=3.15.1` or ensure the list passed to `add_rows()` is not empty before calling.
affects: <3.15.1
gotchaIn versions prior to 3.14.0, specifying `sortby` directly at class declaration might not have been correctly applied, requiring it to be set after instantiation or via `get_string()` arguments.
fix
Upgrade to `prettytable>=3.14.0` or set `sortby` explicitly on the table instance (`table.sortby = "Column"`) after initialization or when calling `get_string()`.
affects: <3.14.0
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'prettytable'
The 'prettytable' package is not installed in the Python environment where the script is being executed.
fix
pip install prettytable
AttributeError: 'module' object has no attribute 'PrettyTable'
A local Python file named 'prettytable.py' exists in the same directory as your script, shadowing the installed 'prettytable' library and preventing the correct module from being imported.
fix
Rename your local file from 'prettytable.py' to something else (e.g., 'my_table_script.py') and delete any associated '.pyc' files.
TypeError: PrettyTable.add_row() takes 2 positional arguments but X were given
The 'add_row()' method expects a single iterable (like a list or tuple) containing all the values for the row as its argument, but individual values are being passed as separate arguments.
fix
Pass a list or tuple of values to 'add_row()', for example: `table.add_row([value1, value2, value3])`.
AttributeError: 'module' object has no attribute 'set_field_names'
The 'set_field_names()' method was deprecated and removed in PrettyTable version 0.6. Field names are now set directly via the 'field_names' attribute.
fix
Instead of `table.set_field_names(['Header 1', 'Header 2'])`, use `table.field_names = ['Header 1', 'Header 2']`.
Upgrade
Version history
3.18.0latest on PyPI · released Jun 22, 2026
Audit
Dependencies
wcwidthrequiredUsed for correct width calculation of wide characters in ASCII tables.
Agent activity
20 hits · last 30 days
node
16
Meta
2
Resources
prettytable — pip install prettytable · libregistry