Skip to main content

Render data as clean ASCII/Unicode tables in the terminal with zero configuration

Project description

philiprehberger-text-table

Tests PyPI version License

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"))

Truncation

print(table(headers, rows, max_width=10))

API

Function Description
table(headers, rows, *, style="unicode", max_width=None) Render a table from headers and row data
from_dicts(data, *, style="unicode", max_width=None) Render a table from a list of dictionaries
from_csv(path, *, style="unicode", max_width=None) Read a CSV file and render as a table

Styles: "unicode", "ascii", "markdown", "minimal", "compact"

Development

pip install -e .
python -m pytest tests/ -v

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

philiprehberger_text_table-0.1.7.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

philiprehberger_text_table-0.1.7-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file philiprehberger_text_table-0.1.7.tar.gz.

File metadata

File hashes

Hashes for philiprehberger_text_table-0.1.7.tar.gz
Algorithm Hash digest
SHA256 ac426b25c2440a9ee78443ea8077c5e73d2a00f2a02e994ce85404505237f43c
MD5 2f1a233fc2d0ec5a9dd2405f2a974dd3
BLAKE2b-256 80c331cea7de53fcdbfe4382d2f7e16270b43130a4bc1a15b4e51d6fd79f4895

See more details on using hashes here.

File details

Details for the file philiprehberger_text_table-0.1.7-py3-none-any.whl.

File metadata

File hashes

Hashes for philiprehberger_text_table-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 859911cf688e73cc74218b651ce89f6e542e3ab6bdca2e02b7d358f88ccb2d99
MD5 de0bb97b77ec9d18c0743acbaf89e24b
BLAKE2b-256 9163be9ff764adafe6be829a5e5a9d3ea7ba29018b01549219d37ea5c5873f2a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page