Skip to main content

craftable - craft elegant tables using format strings

Project description

craftable — craft elegant tables using format strings

Generate clean, flexible text tables in the terminal or in text files using a familiar, Python-native formatting approach. craftable focuses on attractive and predictable output, zero dependencies, a simple and elegant API, and fast rendering without requiring a full TUI library.

  • Small, zero-dependency API
  • Works with plain Python data (lists/rows)
  • Built-in adapters for dicts, dataclasses, numpy, pandas, SQL, and more
  • Column definitions use Python's format mini-language
  • Multiple built-in styles: no borders, box drawing, rounded, ASCII, Markdown
  • Supports wrapping, truncation, alignment, and auto-fill columns
  • Simple, but flexible and extensible to meet most any use case

Quick example

from craftable import get_table

data = [
    ["Alice", 147000, .035, "Engineer"],
    ["Bob", 88000, .0433, "Designer"],
]

print(get_table(
    data,
    header_row=["Name", "Salary", "Adj", "Title"],
    col_defs=["A","<$ (,)", ">.2%", "A"],
    table_width=50,
))

Output:

      Name     │   Salary  │  Adj  │    Title     
───────────────┼───────────┼───────┼──────────────
 Alice         │ $ 147,000 │ 3.50% │ Engineer     
 Bob           │ $  88,000 │ 4.33% │ Designer     

Data Adapters

Convert Python data structures directly into tables with built-in adapters:

from craftable import get_table
from craftable.adapters import from_dicts

# List of dictionaries (handles missing keys gracefully)
data = [
    {"name": "Alice", "age": 30, "city": "LA"},
    {"name": "Bob", "age": 25},  # missing 'city'
]

rows, headers = from_dicts(data)
print(get_table(rows, header_row=headers))

Adapters available for: dicts, dataclasses, numpy arrays, pandas/polars DataFrames, SQL cursors, and more. See the Adapters documentation for details.

When to use craftable

Use craftable when you need reliable text tables in logs, CLIs, or scripts, and want the control of Python format specs without heavy UI tooling. If you need interactive widgets or color/styling, consider pairing with Rich — but for static tables, craftable is intentionally simple and fast.

Getting Started

Read the online documentation:

https://ptyork.github.io/craftable

Available as craftable in PyPI with zero additional dependencies, so you can install or add to your project using your favorite package manager.

pip

pip install craftable

poetry

poetry add craftable

uv

uv add craftable

Or if using uv pip:

uv pip install craftable

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

craftable-0.2.1.tar.gz (25.3 kB view details)

Uploaded Source

Built Distribution

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

craftable-0.2.1-py3-none-any.whl (35.6 kB view details)

Uploaded Python 3

File details

Details for the file craftable-0.2.1.tar.gz.

File metadata

  • Download URL: craftable-0.2.1.tar.gz
  • Upload date:
  • Size: 25.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.24

File hashes

Hashes for craftable-0.2.1.tar.gz
Algorithm Hash digest
SHA256 68d32219f2a2f669cf7a23bd85b6c86c47e9dd8343854e6c6c3473dd85f55ad7
MD5 0ffa8d9ddbe6fcee8ed15661e21be62f
BLAKE2b-256 fa70d8b80e33bf2c15d797f550445c1dccb0d8df92d1835542347a97ce3af96a

See more details on using hashes here.

File details

Details for the file craftable-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: craftable-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 35.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.24

File hashes

Hashes for craftable-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3f277cf4f0b64f8d3e19be4543d1ca60eecec611955657da1a213d9f5ac97834
MD5 300144812443b0fa22f9c14a61190af6
BLAKE2b-256 c1c10ce6903bc6c59fbc9ae6a32da7b3275f91b7e4af56043ce2b5a539fb5aaa

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