PTable

0.9.2 · maintenance · verified Thu Apr 16

PTable is a simple Python library designed to make it quick and easy to represent tabular data in visually appealing ASCII tables. It was originally forked from PrettyTable and maintains API compatibility. The current version is 0.9.2, with its last release in 2015, indicating a largely inactive or maintenance-only development cadence.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates creating a PrettyTable instance, defining column headers using `field_names`, adding data row by row with `add_row`, and then printing the table to the console. It also shows how to get an HTML string representation.

from prettytable import PrettyTable

# Create a new table
x = PrettyTable()

# Set field names
x.field_names = ["City name", "Area", "Population", "Annual Rainfall"]

# Add rows
x.add_row(["Adelaide", 1295, 1158259, 600.5])
x.add_row(["Brisbane", 5905, 1857594, 1146.4])
x.add_row(["Darwin", 112, 120900, 1714.7])

# Print the table (implicitly calls __str__ for ASCII representation)
print(x)

# Get HTML string representation
html_table = x.get_html_string()
# print(html_table) # Uncomment to see HTML output

view raw JSON →