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, including image/sparkline support and a
Jupyter HTML preview.
Install
Install the latest release from PyPI:
uv add tytable
Or with pip:
pip install tytable
For generated plots and sparklines, install the optional extra. Embedding existing
image files with .images() needs no additional Python dependencies:
uv add "tytable[images]"
From a cloned checkout, run:
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 in a script, or let `tab` be the last line of a Jupyter cell for a preview.
tab.save("report_assets/products.typ")
tab
The .typ file can be #included in a Typst report and compiled as part of the
whole document.
Conventions
- 0-based row indexing:
i=0is the first data row (the row after the column-name header). Usei="header"for the column-name row, negative ints for column-group header rows (-1is the innermost row, immediately above the column-name header; increasingly negative values move upward). - Column selection by name:
j="Score"(preferred);j=0selects the first column by position. - Method chaining:
.style(),.fmt(),.group(), and the.theme_*()methods all returnself..render()/.save()are terminal. - Readable defaults: text columns are left-aligned and numeric columns are
right-aligned, including their headers. Explicit
.style(align=...)calls override these dtype-based defaults. - 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". Usefigure=Falsefor an unnumbered table; captions and labels cannot be combined with it.
Documentation
A practical guide with rendered examples (source followed by result) from easy to
complex, a task-oriented API reference, and an R-tinytable comparison table live in
the PDF built from docs/main.typ:
- Always-current build (HEAD): https://einmaulwurf.github.io/tytable/
- Versioned (latest release): https://github.com/EinMaulwurf/tytable/releases/latest/download/tytable-docs.pdf
Build locally (requires the typst CLI, install from here):
make docs
# → docs/tytable-docs.pdf
Starting with version 1.0, documented public APIs remain backward compatible throughout the 1.x series; breaking changes are reserved for 2.0.
Coming from R tinytable
tt(df) ↔ tt(data), .style() ↔ style_tt(), .fmt() ↔ format_tt(),
.group() ↔ group_tt(), and .theme_striped() / .theme_grid() correspond
to 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
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 tytable-1.0.0.tar.gz.
File metadata
- Download URL: tytable-1.0.0.tar.gz
- Upload date:
- Size: 254.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
63a901d933ddb0ea8c06d890366ab80554bf14e4007b7489c1d6e97ac06bbdde
|
|
| MD5 |
741e9095992af4715b0266e5fa964b4f
|
|
| BLAKE2b-256 |
a79fb96f59868852c4dabe6c06036cd4e05c06fc3c8f387a8acb13be978778b2
|
Provenance
The following attestation bundles were made for tytable-1.0.0.tar.gz:
Publisher:
release.yml on EinMaulwurf/tytable
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tytable-1.0.0.tar.gz -
Subject digest:
63a901d933ddb0ea8c06d890366ab80554bf14e4007b7489c1d6e97ac06bbdde - Sigstore transparency entry: 2184931534
- Sigstore integration time:
-
Permalink:
EinMaulwurf/tytable@67154384dc7e94ac0db78e049fc9a8f4e685e24f -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/EinMaulwurf
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@67154384dc7e94ac0db78e049fc9a8f4e685e24f -
Trigger Event:
push
-
Statement type:
File details
Details for the file tytable-1.0.0-py3-none-any.whl.
File metadata
- Download URL: tytable-1.0.0-py3-none-any.whl
- Upload date:
- Size: 65.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8db4e61a72aeaaf6e488d77b5b092035cceee7a7ced2ec3d1b44829c74df003e
|
|
| MD5 |
66c7f6fbc08173fc0d73a3408fc2a233
|
|
| BLAKE2b-256 |
2335c794d8b59d1a81f8d6c130def512869544431348fb61ade09880f6284368
|
Provenance
The following attestation bundles were made for tytable-1.0.0-py3-none-any.whl:
Publisher:
release.yml on EinMaulwurf/tytable
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tytable-1.0.0-py3-none-any.whl -
Subject digest:
8db4e61a72aeaaf6e488d77b5b092035cceee7a7ced2ec3d1b44829c74df003e - Sigstore transparency entry: 2184931682
- Sigstore integration time:
-
Permalink:
EinMaulwurf/tytable@67154384dc7e94ac0db78e049fc9a8f4e685e24f -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/EinMaulwurf
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@67154384dc7e94ac0db78e049fc9a8f4e685e24f -
Trigger Event:
push
-
Statement type: