Skip to main content

A simple callable library for creating formatted tables with box-drawing characters

Project description

tablur

a simple, callable python library for creating beautifully formatted tables with box-drawing characters.

features

  • callable interface: use tablur() directly as a function
  • create tables with box-drawing characters (╭─╮│├┼┤┴╰)
  • support for optional headers and footers
  • automatic column width calculation
  • three input formats: column-based, dictionary, and row-based
  • returns formatted strings (no automatic printing)
  • lightweight and blazingly fast

installation

pip install tablur

usage

column-based format (default)

from tablur import tablur

# data is defined as a list of tuples where each tuple contains `(column_name, column_data)`
data = [
    ("Name", ["Alice", "Bob", "Charlie"]),
    ("Age", [25, 30, 35]),
    ("City", ["New York", "London", "Tokyo"]),
    ("Salary", [50000, 60000, 70000]),
]

# using the `tablur` function
table = tablur(
    data,
    header="Employee Directory",
    footer="Total: 3 employees",
    chars=["╭", "╮", "╰", "╯", "├", "┤", "┬", "┴", "┼", "─", "│"] # this is the default, make sure you use this format
)
print(table)

output:

╭───────────────────────────────────╮
│        Employee Directory         │
├─────────┬─────┬──────────┬────────┤
│ Name    │ Age │ City     │ Salary │
├─────────┼─────┼──────────┼────────┤
│ Alice   │ 25  │ New York │ 50000  │
│ Bob     │ 30  │ London   │ 60000  │
│ Charlie │ 35  │ Tokyo    │ 70000  │
├─────────┴─────┴──────────┴────────┤
│        Total: 3 employees         │
╰───────────────────────────────────╯

dictionary format

from tablur import tablur

# data can also be a dictionary where keys are column names and values are lists of data
data = {
    "Name": ["Alice", "Bob", "Charlie"],
    "Age": [25, 30, 35],
    "City": ["New York", "London", "Tokyo"],
    "Salary": [50000, 60000, 70000],
}

# using the `tablur` function with dictionary
table = tablur(
    data,
    header="Employee Directory",
    footer="Total: 3 employees"
)
print(table)

output:

╭───────────────────────────────────╮
│        Employee Directory         │
├─────────┬─────┬──────────┬────────┤
│ Name    │ Age │ City     │ Salary │
├─────────┼─────┼──────────┼────────┤
│ Alice   │ 25  │ New York │ 50000  │
│ Bob     │ 30  │ London   │ 60000  │
│ Charlie │ 35  │ Tokyo    │ 70000  │
├─────────┴─────┴──────────┴────────┤
│        Total: 3 employees         │
╰───────────────────────────────────╯

row-based format

from tablur import simple

# data is just a list of rows, where each row is a list of values
data = [
    ["Alice", 25, "New York"],
    ["Bob", 30, "London"],
    ["Charlie", 35, "Tokyo"]
]

# with simple, you can define the headers explicitly or not (they default to indices)
table = simple(data, headers=["Name", "Age", "City"])
print(table)

[!NOTE] The simple() function also supports dictionary format, just like tablur().

output:

╭─────────┬─────┬──────────╮
│ Name    │ Age │ City     │
├─────────┼─────┼──────────┤
│ Alice   │ 25  │ New York │
│ Bob     │ 30  │ London   │
│ Charlie │ 35  │ Tokyo    │
╰─────────┴─────┴──────────╯

license

mit, you can do whatever you want with the code :D

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

tablur-1.1.0.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

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

tablur-1.1.0-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file tablur-1.1.0.tar.gz.

File metadata

  • Download URL: tablur-1.1.0.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for tablur-1.1.0.tar.gz
Algorithm Hash digest
SHA256 a1c262d5798a072626d52666325de73afbad5d0bf4833b4e7b21aeef0d73be87
MD5 ff65e220f6c9cabc16afe8d27673df60
BLAKE2b-256 3ec8569a5a374698826c948d7c4f11a87890c5ffe3932f43a67097fcfad2ba19

See more details on using hashes here.

File details

Details for the file tablur-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: tablur-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for tablur-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 de7e54732e8cb3d3014f0329b53ad645e892b50e76ff527fae854c1f87097760
MD5 93daf324e4fcff76c331a614e0294707
BLAKE2b-256 e343137cd1c0cdae9142ca49cef05691dce8e9bdad21cec986b64e74ba6ae1b2

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