span-table is a lightweight Python helper for rendering ASCII tables with merged cells using Rich-style markup.
Project description
span-table
span-table is a lightweight Python helper for rendering ASCII tables with merged cells using Rich-style markup.
Features
- Render table layouts with custom merged spans
- Support multi-line cell content
- Uses
richbox styles for flexible borders - Compatible with Python
>=3.14
Installation
pip install span-table
Quick Start
from span_table import span_table
from rich import print
table = [
["Header 1", "Header 2", "Header3", "Header 4"],
["row 1", "column 2", "column 3", "column 4"],
["row 2", "Cells span columns.", "", ""],
["row 3", "Cells\nspan rows.", "- Cells\n- contain\n- blocks", ""],
["row 4", "", "", ""]
]
# Spans are defined as ((start_row, start_col), (end_row, end_col)) with zero-based indexes
my_spans = [
((2, 1), (2, 3)),
((3, 1), (4, 1)),
((3, 2), (4, 3)),
]
print(span_table(table, my_spans))
This renders:
┌──────────┬────────────┬──────────┬──────────┐
│ Header 1 │ Header 2 │ Header3 │ Header 4 │
├──────────┼────────────┼──────────┼──────────┤
│ row 1 │ column 2 │ column 3 │ column 4 │
├──────────┼────────────┴──────────┴──────────┤
│ row 2 │ Cells span columns. │
├──────────┼────────────┬─────────────────────┤
│ row 3 │ Cells │ - Cells │
├──────────┤ span rows. │ - contain │
│ row 4 │ │ - blocks │
└──────────┴────────────┴─────────────────────┘
Advanced Usage
from span_table import span_table
from rich import print
table = [
["Time", "[on red]Height[/]", "", "[on green]Weight[/]", ""],
["", "Total", "Change", "Total", "Change"],
["15:30", "1", "2", "3", "4"]
]
spans = [
((0, 0), (1, 0)),
((0, 1), (0, 2)),
((0, 3), (0, 4))
]
print(span_table(table, spans, border_style="red"))
This renders:
┌───────┬────────────────┬────────────────┐
│ Time │<red bg> Height │<Green BG>Weight│
│ ├───────┬────────┼───────┬────────┤
│ │ Total │ Change │ Total │ Change │
├───────┼───────┼────────┼───────┼────────┤
│ 15:30 │ 1 │ 2 │ 3 │ 4 │
└───────┴───────┴────────┴───────┴────────┘
API
span_table(data, spans, box=rich_box.SQUARE, border_style=str | Style) -> str
Render a text table with optional merged cells.
data:list[list[str]]— table rows and columnsspans:list[tuple[tuple[int, int], tuple[int, int]]]— list of merge regionsbox:rich.box.Box— optional Rich box style such asbox.SQUAREborder_style:strorrich.style.Style- optional style for borders
Span rules
- Each span is a rectangular region defined by a start and end coordinate
- Coordinates are zero-based:
(row_index, column_index) - Spans can cover a single cell or multiple cells
- Spans must be within the table bounds
Rich markup support
Cell values may include Rich markup tags such as [bold], [italic], or color tags. The library preserves markup while measuring text layout.
Notes
- Ensure each row has the same number of columns
- Non-merged cells may be omitted from
spans - The library automatically fills any cells not included in spans as standard individual cells
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 span_table-0.4.0.tar.gz.
File metadata
- Download URL: span_table-0.4.0.tar.gz
- Upload date:
- Size: 27.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ca68b5b322da43e5bfaece42811d0a3405b3cf5ed7942e610bc9e97d10c61ced
|
|
| MD5 |
f03137d45ebc3a9079a60c9cefb039c5
|
|
| BLAKE2b-256 |
519e36ae2dac9e9d581b0f46e4c7659d1c81de415e31f18abb92510bc9351bff
|
File details
Details for the file span_table-0.4.0-py3-none-any.whl.
File metadata
- Download URL: span_table-0.4.0-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c8d08775b9ca4360d1fabc452304909673e4b6ad504528f1c8de82d2c7003aba
|
|
| MD5 |
4117b733e845a3c0b68ea5926f75684b
|
|
| BLAKE2b-256 |
599549cc5b9d6b68e8d254134df80ad3bcfc6a84e2aadc9cc2019992bddfe017
|