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.

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

Methods

The following table methods allow you to manipulate a table.

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

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

Example

General Syntax: element.property.attribute = value

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.

Import/Export

Tabling supports import and export in multiple file formats—CSV, TSV, JSON, HTML, Markdown, Plain Text, XLSX, and SQLite—via the tabling.io module.

Examples

Exporting

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")

Importing

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")

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.1.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.1-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tabling-2.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 b0542e277831e18254b3a0d27e971c81e2a3a6635c09ea8e0285c15e58c24905
MD5 8a6c176f4ab15ba0d55cc3dbb9da207d
BLAKE2b-256 93765715a79c863cf1899d6ac539a29c7ab25195e39f8df44f89d8f799719025

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tabling-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 16.4 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e8b8e062836665c0e8e48199037e1c144fd9e2e57bd444b23b607d36161b83e5
MD5 b935a4f5f2d65d09c547e313019f51e6
BLAKE2b-256 be281182c8159ab086a3b2820a6b53e19c032fc68d21a229d396bce6133cdabf

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