Render data as clean ASCII/Unicode tables in the terminal with zero configuration
Project description
philiprehberger-text-table
Render data as clean ASCII/Unicode tables in the terminal with zero configuration.
Installation
pip install philiprehberger-text-table
Usage
from philiprehberger_text_table import table
headers = ["Name", "Age", "City"]
rows = [
["Alice", 30, "New York"],
["Bob", 25, "London"],
["Charlie", 35, "Tokyo"],
]
print(table(headers, rows))
Output:
┌─────────┬─────┬──────────┐
│ Name │ Age │ City │
├─────────┼─────┼──────────┤
│ Alice │ 30 │ New York │
│ Bob │ 25 │ London │
│ Charlie │ 35 │ Tokyo │
└─────────┴─────┴──────────┘
From dictionaries
from philiprehberger_text_table import from_dicts
data = [
{"name": "Alice", "score": 95},
{"name": "Bob", "score": 87},
]
print(from_dicts(data))
From CSV
from philiprehberger_text_table import from_csv
print(from_csv("data.csv"))
Styles
# ASCII style
print(table(headers, rows, style="ascii"))
# Markdown style
print(table(headers, rows, style="markdown"))
# Minimal style (no borders)
print(table(headers, rows, style="minimal"))
# Compact style (no outer borders)
print(table(headers, rows, style="compact"))
Column alignment
# Override auto-detection for all columns
print(table(headers, rows, align="center"))
# Per-column alignment
print(table(headers, rows, align=["left", "center", "right"]))
From CSV string
from philiprehberger_text_table import from_csv_string
csv_data = "Name,Age\nAlice,30\nBob,25"
print(from_csv_string(csv_data))
Truncation
print(table(headers, rows, max_width=10))
API
| Function | Description |
|---|---|
table(headers, rows, *, style="unicode", max_width=None, align=None) |
Render a table from headers and row data |
from_dicts(data, *, style="unicode", max_width=None, align=None) |
Render a table from a list of dictionaries |
from_csv(path, *, style="unicode", max_width=None, align=None) |
Read a CSV file and render as a table |
from_csv_string(text, *, style="unicode", max_width=None, align=None) |
Render a table from CSV string content |
Styles: "unicode", "ascii", "markdown", "minimal", "compact"
Alignments: "left", "right", "center" (default: auto-detect, numeric columns right-aligned)
Development
pip install -e .
python -m pytest tests/ -v
Support
If you find this project useful:
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 philiprehberger_text_table-0.2.0.tar.gz.
File metadata
- Download URL: philiprehberger_text_table-0.2.0.tar.gz
- Upload date:
- Size: 8.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
42b057081e9d237c855090d79866978af19743bfbd1fb0b58233a394fd8ca75d
|
|
| MD5 |
735d1c87c08b048f6b37dea3e5ebba4a
|
|
| BLAKE2b-256 |
1f9d5845cb36036b73d243d37dfdcdf515a9007ddfd738e4d71b2ffe1a4eee7a
|
File details
Details for the file philiprehberger_text_table-0.2.0-py3-none-any.whl.
File metadata
- Download URL: philiprehberger_text_table-0.2.0-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1007357c1661a744510f927d1935a64651ff3076d9892278fd62f2b3effd2b78
|
|
| MD5 |
93906c81b54175b8016e1081401639bc
|
|
| BLAKE2b-256 |
51caa2324f1d8cb4b89613c13bbb794539537cf3515b6007c5d95567940d3d37
|