A simple library for creating formatted tables with box-drawing characters
Project description
tablur
a simple python library for creating beautifully formatted tables with box-drawing characters.
features
- simple interface: use
tablur()andsimple()functions - 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 liketablur().
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
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 tablur-1.2.0.tar.gz.
File metadata
- Download URL: tablur-1.2.0.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ca7272d697b2d6edff428bfcb5a9a556c67ffd875dc09919c99dd4897c9eb0bc
|
|
| MD5 |
d9eb178ef3e3978263807434097214bb
|
|
| BLAKE2b-256 |
0580607d715212936ddbce00ef7b998aa2046c368fa443b31170cc636e267fe4
|
File details
Details for the file tablur-1.2.0-py3-none-any.whl.
File metadata
- Download URL: tablur-1.2.0-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b3907870639ecdb53f80024d957ce599117e8c71958c166dae1b2e5b162deddc
|
|
| MD5 |
136001fe33a136b1377a51f06f6dacc4
|
|
| BLAKE2b-256 |
23496b48502da9c790318b532f77eacfeb1c214efbede2f4c06c32ef06e059fe
|