philiprehberger-cli-table
Format Python data as aligned terminal tables with no dependencies.
Installation
pip install philiprehberger-cli-table
Usage
Dict list mode
from philiprehberger_cli_table import table
data = [
{"name": "Alice", "age": 30, "city": "Berlin"},
{"name": "Bob", "age": 25, "city": "Vienna"},
{"name": "Charlie", "age": 35, "city": "Zurich"},
]
table(data)
# name age city
# ------- --- ------
# Alice 30 Berlin
# Bob 25 Vienna
# Charlie 35 Zurich
Headers + rows mode
from philiprehberger_cli_table import table
table(
headers=["Product", "Price", "Stock"],
rows=[
["Widget", "9.99", "142"],
["Gadget", "24.99", "38"],
],
)
# Product Price Stock
# ------- ----- -----
# Widget 9.99 142
# Gadget 24.99 38
Column alignment
Numeric columns auto-right-align — no align config needed. Pass align only when you want to override the inferred alignment.
from philiprehberger_cli_table import table
table(
data=[
{"item": "Coffee", "qty": 3, "price": "4.50"},
{"item": "Tea", "qty": 12, "price": "2.00"},
],
)
# item qty price
# ------ --- -----
# Coffee 3 4.50
# Tea 12 2.00
# Override inferred alignment when needed
table(
data=[{"item": "Coffee", "qty": 3}],
align={"qty": "center"},
)
Styles
from philiprehberger_cli_table import format_table
# Markdown style
print(format_table(
headers=["Name", "Score"],
rows=[["Alice", "95"], ["Bob", "87"]],
style="markdown",
))
# | Name | Score |
# | ----- | ----- |
# | Alice | 95 |
# | Bob | 87 |
# No borders
print(format_table(
headers=["Name", "Score"],
rows=[["Alice", "95"], ["Bob", "87"]],
style="none",
))
# Name Score
# Alice 95
# Bob 87
# Grid style with Unicode box-drawing borders
print(format_table(
headers=["Name", "Score"],
rows=[["Alice", "95"], ["Bob", "87"]],
style="grid",
))
# ┌───────┬───────┐
# │ Name │ Score │
# ├───────┼───────┤
# │ Alice │ 95 │
# │ Bob │ 87 │
# └───────┴───────┘
Cell truncation
from philiprehberger_cli_table import table
table(
data=[{"description": "A very long description that goes on and on"}],
max_width=20,
)
Wide character support
Supports CJK and other wide Unicode characters with correct column alignment.
Footer / totals row
from philiprehberger_cli_table import table
table(
headers=["Item", "Qty", "Total"],
rows=[
["Coffee", "3", "12.00"],
["Tea", "2", "4.00"],
],
footer=["Total", "5", "16.00"],
)
# Item Qty Total
# ------ --- -----
# Coffee 3 12.00
# Tea 2 4.00
# ------ --- -----
# Total 5 16.00
A footer can also be passed as a dict keyed by header name:
table(
data=[{"item": "Coffee", "n": 3}, {"item": "Tea", "n": 2}],
footer={"item": "Total", "n": 5},
)
API
| Function | Description |
|---|---|
format_table(headers, rows, *, data, align, max_width, style, footer) |
Returns a formatted table as a string |
table(data, headers, rows, **kwargs) |
Prints a formatted table to stdout |
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
headers |
list[str] | None |
None |
Column header names |
rows |
list[list[Any]] | None |
None |
List of row value lists |
data |
list[dict[str, Any]] | None |
None |
List of dicts (keys become headers) |
align |
dict[str, Align] | None |
None |
Per-column alignment: "left", "right", "center" |
max_width |
int | None |
None |
Truncate cell values to this width |
style |
Style |
"simple" |
Border style: "simple", "markdown", "none", "grid" |
footer |
list | dict | None |
None |
Footer row rendered below a divider (totals/summary) |
Development
pip install -e .
python -m pytest tests/ -v
Support
If you find this project useful:
License
Metadata
Release files for philiprehberger-cli-table 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| philiprehberger_cli_table-0.4.0.tar.gz | 189.0 kB | Without provenance | Details for philiprehberger_cli_table-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| philiprehberger_cli_table-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for philiprehberger_cli_table-0.4.0-py3-none-any.whl |
Total release size: 195.7 kB
Release files / philiprehberger_cli_table-0.4.0.tar.gz
| Download URL | philiprehberger_cli_table-0.4.0.tar.gz |
|---|---|
| Size | 189.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ecba8aab1fc54c6455517dad662d67a0339e33ad1822271a33c38573cfbf297e
|
|
BLAKE2b-256 checksum How to use checksums |
80d864f9f2d0d884f3f7889ed3a09ac8d540e0374c24dda1b745ec5ecadc7ca8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Release files / philiprehberger_cli_table-0.4.0-py3-none-any.whl
| Download URL | philiprehberger_cli_table-0.4.0-py3-none-any.whl |
|---|---|
| Size | 6.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d82c0953eb7167688c5ff622fed17db9f3dc186fce8d123bbf6af8f164280bf3
|
|
BLAKE2b-256 checksum How to use checksums |
60745618717d914a6f62289006ecd078f11012c0bef51c9fb17374234b58ab6a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Security for philiprehberger-cli-table 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.