Skip to main content

Typst tables from Polars DataFrames, with a tinytable-inspired API.

Project description

tytable

A small Python library that turns Polars DataFrames into Typst tables, inspired by R's tinytable package. Most of tinytable's styling power, plus image/sparkline support and a Jupyter HTML preview.

Install

uv add git+https://github.com/EinMaulwurf/tytable.git

For development (clone and):

uv sync --all-extras
make test

Quickstart

import polars as pl
from tytable import tt

df = pl.DataFrame({
    "Product": ["A", "B", "C"],
    "Score": [85.43, 72.10, 91.87],
})

tab = (
    tt(df, caption="Product scores", label="product-scores")
    .fmt(j="Score", digits=2)
    .style(j="Score", align="c")
    .style(i=0, bold=True, background="#2c3e50", color="white")
    .save("report_assets/products.typ")
)

# In Jupyter, let `tab` be the last line of a cell to see an HTML preview.
tab

The .typ file can be #imported into a Typst report and compiled as part of the whole document.

Conventions

  • 0-based row indexing: i=0 is the first data row (the row after the column-name header). Use i="header" for the column-name row, negative ints for column-group header rows (-1 is the topmost level).
  • Column selection by name: j="Score" (preferred); j=0 selects the first column by position.
  • Method chaining: .style(), .fmt(), .group(), .theme() all return self. .render() / .save() are terminal.
  • Lazy evaluation: styling, formatting, grouping, and plotting are recorded as intent and replayed in a fixed order at render time. Row indices always refer to the final, visible table.
  • Figure wrapping: Typst tables are figures by default, enabling captions, numbering, and labels such as label="product-scores". Use figure=False for an unnumbered table; captions and labels cannot be combined with it.

Documentation

Full documentation with rendered examples (source + result side-by-side), the complete API reference, and an R-tinytable comparison table live in the PDF built from docs/main.typ:

Build locally (requires the typst CLI):

make docs
# → docs/tytable-docs.pdf

Coming from R tinytable

tt(df)tt(data), .style()style_tt(), .fmt()format_tt(), .group()group_tt(), .theme()theme_tt(). Indexing is 0-based (vs R's 1-based) and columns are selected by name (preferred). The full comparison table is in the PDF above.

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

tytable-0.6.0.tar.gz (231.4 kB view details)

Uploaded Source

Built Distribution

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

tytable-0.6.0-py3-none-any.whl (61.4 kB view details)

Uploaded Python 3

File details

Details for the file tytable-0.6.0.tar.gz.

File metadata

  • Download URL: tytable-0.6.0.tar.gz
  • Upload date:
  • Size: 231.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for tytable-0.6.0.tar.gz
Algorithm Hash digest
SHA256 36faf81dfcc811f7926f787722e46e447eb7d99ff19ab7aaf824184a689f8da4
MD5 a42e5daf5bfeec0ad93808782e2ef90a
BLAKE2b-256 521ecc304585f284a3c18e9539dab5256c6c881f23f8532b4bccc63b3a2c6859

See more details on using hashes here.

Provenance

The following attestation bundles were made for tytable-0.6.0.tar.gz:

Publisher: release.yml on EinMaulwurf/tytable

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

File details

Details for the file tytable-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: tytable-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 61.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for tytable-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 82087d04f09805828c35d86ed33e36d8b44c43e53f01437310352bb5bfd5b03a
MD5 f307d32b52a08de750aa48a1fa1c4135
BLAKE2b-256 d9b548137ee447fc496e3ceb96b6aeb3b0bde430a9792f462df55e648971e049

See more details on using hashes here.

Provenance

The following attestation bundles were made for tytable-0.6.0-py3-none-any.whl:

Publisher: release.yml on EinMaulwurf/tytable

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