Skip to main content

A Python package for printing formatted CLI tables with ANSI colors

Project description

Tuible

A Python package for printing formatted CLI tables with ANSI colors.

Features

  • Print single table lines or multi-row table blocks
  • ANSI color support for borders and data
  • Customizable column widths and alignment
  • head formatting with underline styles
  • Auto-sizing based on content
  • Multi-row cells using colon prefix syntax

Installation

pip install tuible

Or using uv:

uv pip install tuible

Usage

Python API

from tuible import print_line, print_block, print_table

# Print a single line
print_line(['Name', 'Age', 'City'], colsize=15, color1='36', color2='35')

# Print a table block
rows = [
    ['Name', 'Age', 'City'],
    ['John', '25', 'New York'],
    ['Jane', '30', 'London']
]
print_block(rows, colsize=-1)  # Auto-size columns

# Print a full table with borders
print_table(heads=['Name', 'Age'], body=[['John', '25'], ['Jane', '30']])

Command Line

The CLI uses a mode-based approach where you can stack different parts of the table.

# Print a single body line
tuible body "Name" "Age" "City"

# Print a header and body
tuible head "Name" "Age" body "John" "25"

# Print a full table with borders
tuible top head "Name" "Age" body "John" "25" bot -cc 2

# With custom colors and formatting
tuible body -ce 31 -cb 32 "Red Border" "Green body"

# The order doesn't matter.
tuible body b1 head h1

Modes

  • body: Print body line
  • head: Print head line
  • top: Print top border
  • bot: Print bottom border

Options

  • -ce <color>: Set edge color (e.g., 34 for blue)
  • -cb <color>: Set body color (e.g., 32 for green)
  • -ch <color>: Set head color (e.g., 33 for yellow)
  • -fb <style>: Set body style (e.g., 4 for underline)
  • -fh <style>: Set head style
  • -fe <chars>: Set edge characters (8 chars: left-right, top-bottom, corners, middle)
  • -size <num>: Set column width (-1 for dynamic)
  • -cc <num>: Set column count
  • -nb: No border (left and right)

Multi-row Cells (Colon Mechanics)

Elements starting with : are treated as continuations in the same column, allowing multi-row content within a single table column.

tuible body "Row 1" ":Row 2" "Other Col"

API Reference

print_line(columns, colsize=25, color1='36', color2='35', format_style='', is_centered=False)

Print a single line of table columns.

print_block(rows, colsize=-1, color1='36', color2='35', format_style='', format_head='4;', is_centered=False)

Print a block of table rows.

print_table(heads=None, body=None, colsize=-1)

Print a complete table with optional heads, body, and borders.

Development

Setup

git clone https://github.com/frank/tuible.git
cd tuible
uv sync

Testing

PYTHONPATH=src uv run pytest

License

MIT License - see LICENSE file for details.

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

tuible-0.1.1.tar.gz (56.9 kB view details)

Uploaded Source

Built Distribution

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

tuible-0.1.1-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file tuible-0.1.1.tar.gz.

File metadata

  • Download URL: tuible-0.1.1.tar.gz
  • Upload date:
  • Size: 56.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for tuible-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c1bab055a759c333ee84f3c98d918ae42d8b821f2d7c8adcf6110db019f41cff
MD5 a3dbe5423ad158105ed021c1ff2f90f9
BLAKE2b-256 2ab76926634950e6bf387d7004cc4a9ade1afb5f52f1c8b5692e9a2c648e8ef9

See more details on using hashes here.

File details

Details for the file tuible-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: tuible-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for tuible-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6d8808c3cac7fd8ffe10ace198fc95062801f4e1f416bc8b2509d4d004eddfd6
MD5 d587575de81ed3f0cb64055fbc859fdd
BLAKE2b-256 4faa3a1ceb06fd4f29ca3d8cdc4fb71c20f51b49e4e435b3f614a7ce1ea8bee5

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