PrettyTable

3.17.0 · active · verified Sat Mar 28

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.

Warnings

Install

Imports

Quickstart

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)

view raw JSON →