Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tablix-0.1.0.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

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

tablix-0.1.0-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

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

Hashes for tablix-0.1.0.tar.gz
Algorithm Hash digest
SHA256 70f46246341d53dee78083670fef16d86512b44c0ba1a6e3a7c2b8c8f072e1c0
MD5 e549c1efe78bb63afe0e43eb93f33f10
BLAKE2b-256 b3eefc3be2c506cb019e21fd19be716e739d3bb92d88c2abf79bd1dca2c1799d

See more details on using hashes here.

Provenance

The following attestation bundles were made for tablix-0.1.0.tar.gz:

Publisher: publish.yml on unexcellent/tablix

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for tablix-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a8ff70dcd7ff9e22d5b05a955e26fe90fce5da7dfcce1bd5c2ccc639bd9f1280
MD5 d886e1dd0a869dff496c3a6178b18f00
BLAKE2b-256 273304a726d12bdb4c84a1244fb0c53f33f466a325568545859b6a5115c6ab88

See more details on using hashes here.

Provenance

The following attestation bundles were made for tablix-0.1.0-py3-none-any.whl:

Publisher: publish.yml on unexcellent/tablix

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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