Skip to main content

Tabling is a Python library, inspired by HTML and CSS, for creating highly customizable tables in the console.

Project description

Tabling

PyPI - Version PyPI - Downloads License Python Versions

Tabling is a Python library, inspired by HTML and CSS, for creating highly customizable tables in the console.

Key Features

  • Add/remove/swap rows, columns, and cells.
  • Find & replace values
  • Sort rows or columns by key
  • Customize background, font, padding, margin, and borders
  • Modify text alignment, direction, spacing, wrapping
  • 5+ border styles: single, double, dashed, dotted, solid
  • 5+ font styles: bold, italic, strikethrough, underline, overline
  • All HTML colors: 140+ names, all RGB values, all HEX codes
  • Import/export from CSV, JSON, HTML, Markdown, Plain text, TSV, XLSX, SQLite
  • Design UIs like how HTML tables were once used before CSS Grid and Flexbox

Installation

pip install tabling

Quick Start

1. Create a Table

from tabling import Table

table = Table(colspacing=1, rowspacing=0)

2. Add Data

table.add_row(("Name", "Age", "Sex"))
table.add_row(("Wesley", 40, "M"))
table.add_row(("Ashley", 22, "F"))
table.add_row(("Lesley", 18, "M"))
table.add_column(("Married", True, False, False))

3. Print the Table

print(table)

table

Table Operations

Method Description
add_row(entries) Add a row
add_column(entries) Add a column
insert_row(index, entries) Insert a row at a position
insert_column(index, entries) Insert a column at a position
remove_row(index) Remove a row
remove_column(index) Remove a column
swap_rows(index1, index2) Swap two rows
swap_columns(index1, index2) Swap two columns
sort_rows(key, start=0, reverse=False) Sort rows by column key
sort_columns(key, start=0, reverse=False) Sort columns by row key
find(value) Highlight matching values
replace(old, new) Replace values
clear() Remove all rows & columns

Styling & Customization

Each element (table, row, column, cell) supports properties similar to CSS:

Property Attribute Type Description
background color str / None Background color
border style str / None Border style
color str / None Border color
font style str / None Font style
color str / None Font color
margin left int Margin to the left
right int Margin to the right
top int Margin to the top
bottom int Margin to the bottom
inline tuple Margin to the left & right
block tuple Margin to the top & bottom
padding left int Padding to the left
right int Padding to the right
top int Padding to the top
bottom int Padding to the bottom
inline tuple Padding to the left & right
block tuple Padding to the top & bottom
text justify str Horizontal alignment
align str Vertical alignment
wrap bool Whether to wrap
visible bool Whether to show
reverse bool Whether to reverse direction
letter_spacing int Spaces between letters
word_spacing int Spaces between words


General Syntax: element.property.attribute = value

Example

Tip: A table behaves like a list of rows, and a row behaves like a list of cells—both support indexing, slicing, and iteration.

table.border.style = "single"
table[0].font.style = "bold"
for row in table[1:]:
    row.border.top.style = "single"
    row[1].text.justify = "center"
    row[2].text.justify = "center"

customized-table

Explore Tabling Templates for ready-made table styles.

File I/O

Tabling supports multiple file formats via the tabling.io module.

Supported Formats

  • CSV, TSV, JSON, HTML, Markdown, Plain text, XLSX, SQLite

Export Example

from tabling import Table
from tabling.io import csv, tsv, json, html, md, txt, xlsx, sqlite

table = Table(colspacing=1, rowspacing=0)
# Add Data & customize...

csv.dump(table, "table.csv")
tsv.dump(table, "table.tsv")
json.dump(table, "table.json")
html.dump(table, "table.html")
md.dump(table, "table.md")
txt.dump(table, "table.txt")
xlsx.dump(table, "table.xlsx")
sqlite.dump(table, "table.db", "title")

Import Example

from tabling import Table
from tabling.io import csv, tsv, json, html, md, xlsx, sqlite

table = Table(colspacing=1, rowspacing=0)

csv.load(table, "table.csv")
tsv.load(table, "table.tsv")
json.load(table, "table.json")
html.load(table, "table.html")
md.load(table, "table.md")
xlsx.load(table, "table.xlsx")
sqlite.load(table, "table.db", "title")

Contributing

Contributions, suggestions, and issues are welcome! See CONTRIBUTING.md.

License

This project is licensed under the MIT License. See the LICENSE for full 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

tabling-2.0.0.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

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

tabling-2.0.0-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

Details for the file tabling-2.0.0.tar.gz.

File metadata

  • Download URL: tabling-2.0.0.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for tabling-2.0.0.tar.gz
Algorithm Hash digest
SHA256 fcf5acadebfb4d919789fba11d75ec14348def2381aa4813347f3ba2f453a0ec
MD5 3641be2105a9d36a78ab22700ac2a7bf
BLAKE2b-256 38364f005b94579a5e9766c2ac37962208d9f202f26fa1d8a477f2bc0f637892

See more details on using hashes here.

File details

Details for the file tabling-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: tabling-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 16.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for tabling-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 577099591a24ee30bcdcbd708c8b40aaf591c50254cb1a8938d7a164f7cd706e
MD5 4db14ffbaf57cadcb2c815e69bd89cc9
BLAKE2b-256 c9984e3fea7127f47dbca2dfea2694db8da05faaaef8c9ce22486e4b3b88443a

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