Skip to main content

A simple module for creating ASCII tables

Project description

vistab

vistab is a lightweight, zero-dependency Python module for creating beautiful text-based ASCII/Unicode tables. It comes out-of-the-box with support for fluid terminal formatting (ANSI escape sequences), coordinate-based discrete cell styling, and guarantees consistent string lengths across dense color variations.

Key Features

  • Zero-Dependency Core: Operates purely off the Python standard library with intelligent fallbacks.
  • Color-Aware Word Wrapping: Dynamically measures and wraps table widths over embedded, invisible ANSI formatting sequences without breaking table geometry.
  • Coordinate-Based Styling API: Colorize rows, columns, headers, or specific cells declaratively (e.g. set_header_style(bg="red", bold=True)).
  • Hierarchical TOML Configurations: Persist your favorite table paddings and layout themes cross-project using a localized .vistab.toml.
  • Advanced Data Parsing: Injects automatic text wrapping, infers scientific datatypes, and parses CSV files.

Detailed Documentation

Looking for an exhaustive configuration breakdown or command-line parser bindings?

Installation

You can install vistab directly via pip:

pip install vistab

Note: For complex Asian/CJK full-width character wrapping support, install the optional component using pip install vistab[cjk].

Quick Start

Getting started with vistab is simple. Initialize a Vistab instance, set up column alignments and paddings, and append your rows.

from vistab import Vistab

table = Vistab(style="round2", padding=1)
# Left, Right, Center alignment
table.set_cols_align(["l", "r", "c"])
# Top, Middle, Bottom vertical alignment
table.set_cols_valign(["t", "m", "b"])

table.add_rows([
    ["Name", "Age", "Nickname"],
    ["Ms\nSarah\nJones", 27, "Sarah"],
    ["Mr\nJohn\nDoe", 45, "Johnny"],
    ["Dr\nEmma\nBrown", 34, "Em"]
])

print(table.draw())

Output:

Note on Web Rendering: We display the raw output below as an image because some package registries (like PyPI) explicitly enforce code-block font stacks (e.g., Source Code Pro) that lack glyphs for Unicode Extended Box Drawing characters. When falling back to secondary system fonts for characters like or , the physical grid mathematically misaligns. On your local terminal—and on full-featured renderers like GitHub or BitBucket—the actual text output mathematically aligns perfectly!

Screenshot: Terminal output displaying a formatted 3-column data matrix. The headers are 'Name', 'Age', and 'Nickname'. The table perfectly encapsulates complex multi-line text blocks across individual cells mapping 'Sarah Jones' directly alongside her age, wrapped inside perfectly aligned rounded Unicode border geometries.

Cookbook Examples

While Vistab excels at rendering arrays, it's also a data-aware formatting engine. Because the API uses a fluent architecture, you can chain multiple logic mutations without intermediate variables.

1. Data Modification & Sorting

You can completely replace data sets or sequentially sort physical rows tracking exact coordinate values without needing pandas overhead:

table = Vistab(style="round", padding=1)

# Sort the array tracking the second column (col_idx=1) descending...
table.set_rows(my_messy_csv_data, header=True).sort_by(1, reverse=True)

2. Output Formatting & Safe Dimensional Windows

Sometimes querying SQL leaves us with extensive data dimensions. We can protect logging interfaces elegantly:

# Force-limit outputs protecting CLI limits! 
table.set_max_rows(10).set_max_cols(5)

3. Shorthand Styling & Native Formatting

You don't need to pass massive syntax strings to evaluate layout injections:

# Conditionally highlight physical elements:
for i, condition in enumerate(my_events):
    table.color_row(i, bg="red" if condition == 'CRITICAL' else None)

# Make the header globally bold instantly:
table.bold_header()

Coordinate-Based Cell Styling

vistab supports a fluent, declarative API to inject background colors, foreground colors, and text styles (like bolding and underlining) targeting specific grids—ranging from individual cells, whole rows, columns, headers, or borders.

Styling Demo

Coordinate-Based Word Wrapping (Nested Tables)

If you need absolute structural control over spatial layouts—for example, if you are embedding pre-rendered ASCII tables inside the cells of another Vistab—you can bypass the internal word-wrapping engine entirely using coordinate mapping.

By setting wrap=False on specific axes, Vistab guarantees it will preserve your structural spacing verbatim without snapping or aggressively pruning layouts:

# Globally bypass word-wrapping for the entire table
table.set_table_wrap(False)

# Or target specific structural coordinates
table.set_row_wrap(0, False)
table.set_col_wrap(2, False)
table.set_cell_wrap(0, 1, False)

If a cell bypassed with wrap=False exceeds table.max_width, Vistab uses a constraint router (table.on_wrap_conflict = "warn") that securely drops trailing characters while reconstructing your internal ANSI styling sequences to prevent terminal boundary collapse.

Hierarchical Configuration System

Stop re-typing your constructor arguments! vistab actively scans your execution environment for TOML configurations.

It searches [./.config/vistab.toml, ./.vistab.toml, ~/.config/vistab.toml, ~/.vistab.toml] for configurations without external dependencies.

You can generate a template configuration file to test using the CLI command:

vistab --create-config .vistab.toml

Built-in Structural Themes

vistab comes with predefined structural themes including light, bold, double, ascii, round2, markdown, and others.

You can view a full structural geometry matrix printed on your terminal by executing:

vistab -L

Available Styles

The Curated Color Theme Matrix

In addition to ASCII-structural styles, Vistab dynamically computes 18 color layout themes utilizing Zebra-Striping. You can paint entire layouts instantly using .apply_theme().

The library supports three base color palettes (ocean, forest, minimalist). Each color palette is distributed across six visual geometries matching the systematic format <palette>-<striping>-<index>. For example:

  • table.apply_theme("ocean") (Default Alternating Zebra Rows)
  • table.apply_theme("ocean-index") (Alternating Rows + First Column Index Highlight applied)
  • table.apply_theme("ocean-cols") (Alternating Column Striping)
  • table.apply_theme("ocean-solid") (Static Background, No striping)

If these 18 themes aren't enough, you can dynamically construct custom matrices by pushing a dictionary configuration directly into the global static boundary Vistab.THEMES["my_blue_theme"] = {...} in your own scripts.

View the curated themes rendered stacked by executing:

vistab -M

Theme Output

Applying Themes via CLI

You can inject these structural formats directly onto raw CSVs leveraging the command line endpoints:

# Parsing files iteratively via positional bindings
vistab data.csv --theme ocean-cols-index --style round

# Routing pipes over STDIN straight from bash
echo -e "Value,Metric\n99,Speed" | vistab --theme minimalist

Discovering Output Colors (CLI)

Because terminal color renderings vary across different user host profiles and color palettes, vistab comes packaged with a native matrix test exposing every foreground, background, and styling text option you can safely deploy.

You can view the palette directly on the console by executing:

vistab -C

Defined Colors

ANSI Color Layout Support

A major benchmark advantage of vistab is native, invisible terminal styling support. Common ASCII libraries frequently break their visual wrapper alignments when raw terminal colors are embedded because they incorrectly count invisible geometry bytes.

You can view a comprehensive color-wrapping conformance test demonstrating dynamic alignment across complex CJK blocks by executing:

vistab -T

Test Output

Advanced Formatting (Datatypes)

vistab can infer and parse formatting rules strictly by passing data types, controlling precision dynamically for scientific floats and integers seamlessly.

from vistab import Vistab

table = Vistab(style="ascii")
table.set_cols_dtype(['t', 'f', 'e', 'i', 'a']) 
table.set_cols_align(["l", "r", "r", "r", "l"])

table.add_rows([
    ["text", "float", "exp", "int", "auto"],
    ["alpha", "23.45", 543, 100, 45.67],
    ["beta", 3.1415, 1.23, 78, 56789012345.12],
    ["gamma", 2.718, 2e-3, 56.8, .0000000000128]
])

Detailed API Reference

For the complete list of endpoints, configuration schemas, parameters, and wrapping constraints available in vistab: Please refer to the absolute granular Vistab Core API Documentation

License

This project is licensed under the BSD 3-Clause License. See LICENSE 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

vistab-1.0.3.tar.gz (34.2 kB view details)

Uploaded Source

Built Distribution

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

vistab-1.0.3-py3-none-any.whl (33.7 kB view details)

Uploaded Python 3

File details

Details for the file vistab-1.0.3.tar.gz.

File metadata

  • Download URL: vistab-1.0.3.tar.gz
  • Upload date:
  • Size: 34.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for vistab-1.0.3.tar.gz
Algorithm Hash digest
SHA256 eb9c17b5978f20febbcf3da110e3c4d7196669e6bf550e7d93fcca8583324a20
MD5 e6997bb1a7b04107b34f8414a278b72a
BLAKE2b-256 162c3501337bc5207ad29a0a86d0bbe7906130c94a56fb43fbcece8c73d4e74e

See more details on using hashes here.

File details

Details for the file vistab-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: vistab-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 33.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for vistab-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b4c5cff0d367f6ada71878542e95f50269d94ee7d9edfc2739704f9a5f59bddd
MD5 e1218d17f3936ab4498fff677aec5f47
BLAKE2b-256 95f1f134526d6cce970ba0b4dc984fa34d176f3c4d9bc591c8fdcbb1a13b1a1b

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