A python package for generating structurally complex tables.
Project description
Standout Features
Yes, this is yet another table renderer in python just like tabulate, prettytable and many others. However, this one has some unique features that the others lack.
- Fine-Grained Formatting: You can apply formatting to entire rows, columns or on a per field basis. Want to highlight a specific field by making it bold? No problem. Boss wants the header row extra special? Let him have it.
- Field Merging: With tablix you can you can merge multiple consecutive fields in the same column. This is especially usefull to signify multiple rows belong to the same category.
In short
| Feature | Tablix | Others |
|---|---|---|
| Rendering in Dozens of Forms | No | Yes |
| Years of Bugfixing | No | Yes |
| Robust Community Support | No | Yes |
| Fine-Grained Formatting | Hell Yeah | No |
Installation
pip install tablix
Examples
Basic Formatting
By default, a table can be constructed with just items. In this case basic formatting is applied.
from tablix import Table
table = Table.from_list(
[
["Item", "Price"],
["Beer", 1.14],
["Pretzels", 10.89],
]
)
print(table)
╭──────────┬───────╮
│ Item │ Price │
┝━━━━━━━━━━┿━━━━━━━┥
│ Beer │ 1.14 │
├──────────┼───────┤
│ Pretzels │ 10.89 │
╰──────────┴───────╯
Formatting can either be applied per field, per row and/or per column. If those formats overlap, field formatting is applied over row formatting which is applied over column formatting.
from tablix import Table, Format
print(Table.from_list(
[
["Item", "Price"],
[("Beer", Format(align="right")), 1.14],
["Pretzels", 10.89],
]
))
╭──────────┬───────╮
│ Item │ Price │
┝━━━━━━━━━━┿━━━━━━━┥
│ Beer │ 1.14 │
├──────────┼───────┤
│ Pretzels │ 10.89 │
╰──────────┴───────╯
print(Table.from_list(
[
["Item", "Price"],
["Beer", 1.14],
["Pretzels", 10.89],
],
row_formats={1: Format(align="right")},
))
╭──────────┬───────╮
│ Item │ Price │
┝━━━━━━━━━━┿━━━━━━━┥
│ Beer │ 1.14 │
├──────────┼───────┤
│ Pretzels │ 10.89 │
╰──────────┴───────╯
print(Table.from_list(
[
["Item", "Price"],
["Beer", 1.14],
["Pretzels", 10.89],
],
column_formats={0: Format(align="right")},
))
╭──────────┬───────╮
│ Item │ Price │
┝━━━━━━━━━━┿━━━━━━━┥
│ Beer │ 1.14 │
├──────────┼───────┤
│ Pretzels │ 10.89 │
╰──────────┴───────╯
Combining Fields
The standout feature from tablix is the possibility to combine multiple fields of a single
column. This is also handled by the formatting system. All adjacent fields in a single column
which have the same value and a Format with merge_same=True are merged into a single cell
spanning multiple rows.
from tablix import Table, Format
print(Table.from_list(
[
["Category", "Item", "Price"],
["Food", "Brathendl", 10.89],
["Food", "Pretzels", 0.55],
["Drinks", "Beer", 1.14],
["Drinks", "Spezi", 0.89],
],
column_formats={0: Format(merge_same=True)},
))
╭──────────┬───────────┬───────╮
│ Category │ Item │ Price │
┝━━━━━━━━━━┿━━━━━━━━━━━┿━━━━━━━┥
│ Food │ Brathendl │ 10.89 │
│ ├───────────┼───────┤
│ │ Pretzels │ 0.55 │
├──────────┼───────────┼───────┤
│ Drinks │ Beer │ 1.14 │
│ ├───────────┼───────┤
│ │ Spezi │ 0.89 │
╰──────────┴───────────┴───────╯
Output Formats
A Table can be converted to a rendered format using Table.to_[rendered format](). This
returns an object with the type of the renderer. To get the individual rendered lines call
Table.to_[rendered format]().lines(). To write the lines directly into a file call
Table.to_[rendered format]().write_to(path).
from tablix import Table
table = Table.from_list(
[
["Item", "Price"],
["Beer", 1.14],
["Pretzels", 10.89],
]
)
rendered_table = table.to_[rendered_format]()
lines: list[str] = rendered_table.lines()
string: str = str(rendered_table)
rendered_table.write_to(path) # write directly to a file
Terminal
from tablix import Table
table = Table.from_list(
[
["Item", "Price"],
["Beer", 1.14],
["Pretzels", 10.89],
]
)
rendered_table = table.to_terminal()
print(rendered_table)
╭──────────┬───────╮
│ Item │ Price │
┝━━━━━━━━━━┿━━━━━━━┥
│ Beer │ 1.14 │
├──────────┼───────┤
│ Pretzels │ 10.89 │
╰──────────┴───────╯
Markdown
from tablix import Table
table = Table.from_list(
[
["Item", "Price"],
["Beer", 1.14],
["Pretzels", 10.89],
]
)
rendered_table = table.to_markdown()
print(rendered_table)
| Item | Price |
| :------- | :---- |
| Beer | 1.14 |
| Pretzels | 10.89 |
Latex
from tablix import Table
table = Table.from_list(
[
["Item", "Price"],
["Beer", 1.14],
["Pretzels", 10.89],
]
)
rendered_table = table.to_latex()
print(rendered_table)
\begin{table}[h]
\centering
\begin{tabularx}{\textwidth}{|X|l|}
\hline Item & Price \\
\hline Beer & 1.14 \\
\hline Pretzels & 10.89 \\
\hline
\end{tabularx}
\end{table}
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 tablix-0.1.0.tar.gz.
File metadata
- Download URL: tablix-0.1.0.tar.gz
- Upload date:
- Size: 10.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
70f46246341d53dee78083670fef16d86512b44c0ba1a6e3a7c2b8c8f072e1c0
|
|
| MD5 |
e549c1efe78bb63afe0e43eb93f33f10
|
|
| BLAKE2b-256 |
b3eefc3be2c506cb019e21fd19be716e739d3bb92d88c2abf79bd1dca2c1799d
|
Provenance
The following attestation bundles were made for tablix-0.1.0.tar.gz:
Publisher:
publish.yml on unexcellent/tablix
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tablix-0.1.0.tar.gz -
Subject digest:
70f46246341d53dee78083670fef16d86512b44c0ba1a6e3a7c2b8c8f072e1c0 - Sigstore transparency entry: 1149536039
- Sigstore integration time:
-
Permalink:
unexcellent/tablix@0eff1e70f442029172fb27a683219f2146168847 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/unexcellent
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0eff1e70f442029172fb27a683219f2146168847 -
Trigger Event:
push
-
Statement type:
File details
Details for the file tablix-0.1.0-py3-none-any.whl.
File metadata
- Download URL: tablix-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a8ff70dcd7ff9e22d5b05a955e26fe90fce5da7dfcce1bd5c2ccc639bd9f1280
|
|
| MD5 |
d886e1dd0a869dff496c3a6178b18f00
|
|
| BLAKE2b-256 |
273304a726d12bdb4c84a1244fb0c53f33f466a325568545859b6a5115c6ab88
|
Provenance
The following attestation bundles were made for tablix-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on unexcellent/tablix
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tablix-0.1.0-py3-none-any.whl -
Subject digest:
a8ff70dcd7ff9e22d5b05a955e26fe90fce5da7dfcce1bd5c2ccc639bd9f1280 - Sigstore transparency entry: 1149536094
- Sigstore integration time:
-
Permalink:
unexcellent/tablix@0eff1e70f442029172fb27a683219f2146168847 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/unexcellent
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0eff1e70f442029172fb27a683219f2146168847 -
Trigger Event:
push
-
Statement type: