Allows for pretty printing and automatic resizing of tables.
Project description
Python Table Print
A lightweight Python library for generating ASCII tables that automatically adjust their column widths to fit your data.
Installation
pip install python-table-print
Quick Start
PrintTable is the core class — add rows to it, then call get_table() to retrieve the formatted table as a string:
from table import PrintTable, Justification
schedule = PrintTable()
schedule.set_title("Solar System at a Glance")
schedule.add_row("Planet", "Type", "Moons", "Day Length", "Claim to Fame")
schedule.add_row("Mercury", "Terrestrial", "0", "59 days", "Closest to the Sun")
schedule.add_row("Venus", "Terrestrial", "0", "243 days", "Hottest surface")
schedule.add_row("Earth", "Terrestrial", "1", "24 hours", "Only known life")
schedule.add_row("Mars", "Terrestrial", "2", "24.6 hours", "Home of Olympus Mons")
schedule.add_row("Jupiter", "Gas giant", "95", "9.9 hours", "Largest planet")
schedule.add_row("Saturn", "Gas giant", "146", "10.7 hours", "The ringed beauty")
schedule.add_row("Uranus", "Ice giant", "28", "17.2 hours", "Rotates on its side")
schedule.add_row("Neptune", "Ice giant", "16", "16.1 hours", "Farthest from Sun")
schedule.set_column_justification(2, Justification.RIGHT)
print(schedule.get_table())
┌───────────────────────────────────────────────────────────────────┐
│ Solar System at a Glance │
├─────────┬─────────────┬───────┬────────────┬──────────────────────┤
│ Planet │ Type │ Moons │ Day Length │ Claim to Fame │
├─────────┼─────────────┼───────┼────────────┼──────────────────────┤
│ Mercury │ Terrestrial │ 0 │ 59 days │ Closest to the Sun │
│ Venus │ Terrestrial │ 0 │ 243 days │ Hottest surface │
│ Earth │ Terrestrial │ 1 │ 24 hours │ Only known life │
│ Mars │ Terrestrial │ 2 │ 24.6 hours │ Home of Olympus Mons │
│ Jupiter │ Gas giant │ 95 │ 9.9 hours │ Largest planet │
│ Saturn │ Gas giant │ 146 │ 10.7 hours │ The ringed beauty │
│ Uranus │ Ice giant │ 28 │ 17.2 hours │ Rotates on its side │
│ Neptune │ Ice giant │ 16 │ 16.1 hours │ Farthest from Sun │
└─────────┴─────────────┴───────┴────────────┴──────────────────────┘
get_table() returns the table as a plain string, so it can be passed to any function — not just print.
Usage
Header Row
By default, the first row is treated as a header and rendered with a separator below it. This can be toggled via the has_header_row property:
my_table.has_header_row = False
Title
A title can be added above the table with set_title(). It defaults to centre justification:
my_table.set_title("My Title")
To remove the title, call clear_title().
Justification
By default, all cells are left-justified. Justification can be set at four levels of granularity — each level overrides any previously set justification for the affected cells. The Justification enum must be imported alongside PrintTable.
Table-wide
from table import PrintTable, Justification
my_table.set_table_justification(Justification.CENTRE)
Row
my_table.set_row_justification(0, Justification.LEFT)
Column
my_table.set_column_justification(0, Justification.RIGHT)
Cell
my_table.set_cell_justification(1, 1, Justification.LEFT)
Justification for the title can also be set independently:
my_table.set_title_justification(Justification.LEFT)
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file python_table_print-1.0.5.tar.gz.
File metadata
- Download URL: python_table_print-1.0.5.tar.gz
- Upload date:
- Size: 10.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d8ad9dd284c310a481d545330ef4fc50a63fab6657b7f4ca18a87ede655b6e7e
|
|
| MD5 |
a60a98e23bf2d23d81267b1acf5bf47a
|
|
| BLAKE2b-256 |
90928c648c65bc111b95c4ce87177f5c126785a24c299bfa97bc43c60597044a
|
Provenance
The following attestation bundles were made for python_table_print-1.0.5.tar.gz:
Publisher:
python-publish.yml on Zandwhich/Python-Table-Print
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
python_table_print-1.0.5.tar.gz -
Subject digest:
d8ad9dd284c310a481d545330ef4fc50a63fab6657b7f4ca18a87ede655b6e7e - Sigstore transparency entry: 1824291669
- Sigstore integration time:
-
Permalink:
Zandwhich/Python-Table-Print@85406cd7eb22ba01f8b774ad4a50b6d86845db32 -
Branch / Tag:
refs/tags/v1.05 - Owner: https://github.com/Zandwhich
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@85406cd7eb22ba01f8b774ad4a50b6d86845db32 -
Trigger Event:
release
-
Statement type:
File details
Details for the file python_table_print-1.0.5-py3-none-any.whl.
File metadata
- Download URL: python_table_print-1.0.5-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b62469fb96ab380cda37a9177e51bdffaa7842a4bfa7d8614bb3143405cef3a
|
|
| MD5 |
816fcb94e3458db167e61e87c4011393
|
|
| BLAKE2b-256 |
96698e2300b974cd43646163ac1a403489d079e1617bca4d8312a7034b5bd15d
|
Provenance
The following attestation bundles were made for python_table_print-1.0.5-py3-none-any.whl:
Publisher:
python-publish.yml on Zandwhich/Python-Table-Print
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
python_table_print-1.0.5-py3-none-any.whl -
Subject digest:
6b62469fb96ab380cda37a9177e51bdffaa7842a4bfa7d8614bb3143405cef3a - Sigstore transparency entry: 1824291895
- Sigstore integration time:
-
Permalink:
Zandwhich/Python-Table-Print@85406cd7eb22ba01f8b774ad4a50b6d86845db32 -
Branch / Tag:
refs/tags/v1.05 - Owner: https://github.com/Zandwhich
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@85406cd7eb22ba01f8b774ad4a50b6d86845db32 -
Trigger Event:
release
-
Statement type: