terminaltables
terminaltables is a Python library designed to easily draw tables in terminal/console applications from a nested list of strings. It supports multi-line rows and various table styles like ASCII, single-line, double-line, and GitHub Flavored Markdown. The current version is 3.1.10, but the project is no longer actively maintained.
Warnings
- breaking The `terminaltables` project (version 3.1.10 and earlier) is no longer actively maintained since December 2021. Users are strongly encouraged to consider using `terminaltables3` (`pip install terminaltables3`), which is a maintained fork designed to be a drop-in replacement.
- breaking Classes `UnixTable`, `WindowsTable`, and `WindowsTableDouble` were removed and replaced.
- breaking The `padded_table_data` property and `join_row()` method were removed.
- breaking Python 2.6 support was removed.
- gotcha When generating multiple tables in a loop, a common mistake is to create a new `table_data` list and `AsciiTable` object in each iteration. This results in separate, small tables being printed.
Install
-
pip install terminaltables
Imports
- AsciiTable
from terminaltables import AsciiTable
- SingleTable
from terminaltables import SingleTable
- DoubleTable
from terminaltables import DoubleTable
- GithubFlavoredMarkdownTable
from terminaltables import GithubFlavoredMarkdownTable
Quickstart
from terminaltables import AsciiTable
table_data = [
['Heading1', 'Heading2', 'Heading3'],
['Row1 Col1', 'Row1 Col2', 'Row1 Col3'],
['Row2 Col1', 'Row2 Col2 with a long text that wraps', 'Row2 Col3'],
['Row3 Col1', 'Row3 Col2', 'Row3 Col3']
]
table = AsciiTable(table_data)
# You can also set a title
table.title = 'My Awesome Table'
# Adjust column alignment (l=left, c=center, r=right)
# table.justify_columns = {'Heading1': 'left', 'Heading2': 'center'}
print(table.table)