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
Tytable-generated .typ fragments require Typst 0.11.1 or newer to compile. The published documentation PDF is built with Typst 0.15.0.
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
Common number, currency, percentage, date, duration, and unit conventions are available from tytable.formatters, including German output such as 1.023,87 €. Pass them to .fmt(fn=...); see the full guide for options and rendered examples.
Create a standalone PDF, PNG, or SVG directly when the Typst CLI is installed:
tab.compile("products.pdf")
tab.compile("products.png", ppi=200)
Use tab.save("products.typ") instead when the table will be #included in a larger Typst report. See Saving and using a table in Typst for project roots, fonts, page selection, and image handling.
Conventions
- Semantic row selection: non-negative
ivalues are stable 0-based source DataFrame positions, even after row groups are inserted. Omittingi(or usingi="data") selects all source rows. Usei="header",i="groupi",i="groupj", ori="all"for explicit structural selections;groupi(label="A")selects row-group separators by their exact registered label,rowgroup(label="A")selects their member data rows, andgroupj(level=0)selects the first-created, innermost column-group header level. Styling supports every grid row. Formatting and targeted notes support data, row-group, and column-name rows; plots and images support data and row-group rows. Unsupported structural targets raise a clear error when rendered. - Column selection: use original DataFrame names (
j="Score"), 0-based positions (j=0), Polars selectors,regex(pattern)for fail-loud Python regular-expression matching, orcolgroup(label="Results", level=0)for the source columns belonging to registered column groups; display names are presentation-only. - Method chaining:
.style(),.fmt(),.group(), and the.theme_*()methods all returnself..render(),.save(), and.compile()are terminal. - Reusable variants:
.clone()creates an independently configurable table while cheaply sharing Polars' immutable data buffers. - 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.
- 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 and Typstyle CLIs):
make docs
# → docs/tytable-docs.pdf
make docs formats the hand-written .typ sources with Typstyle before compiling them. It uses Tinymist's defaults: a 120-column print width and no prose wrapping. Run make format-docs to format without building the PDF.
Documented public APIs remain backward compatible throughout each major release series. After version 2.0, further breaking changes are reserved for 3.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.
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-3.1.0.tar.gz.
File metadata
- Download URL: tytable-3.1.0.tar.gz
- Upload date:
- Size: 351.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f4c176ef3c9725846095ae2e42fb3367389831af42df9b56dc141493f27566e
|
|
| MD5 |
c4d0d2e7b7682f134d8ce6723978a72c
|
|
| BLAKE2b-256 |
587cf921bbb616aab8a1aa3c27f362aef9e43a136c9d171b7a5d4315abe7db3d
|
Provenance
The following attestation bundles were made for tytable-3.1.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-3.1.0.tar.gz -
Subject digest:
4f4c176ef3c9725846095ae2e42fb3367389831af42df9b56dc141493f27566e - Sigstore transparency entry: 2729965735
- Sigstore integration time:
-
Permalink:
EinMaulwurf/tytable@81d80a0ccff46e63fd65326deff0f5af7ec06bfc -
Branch / Tag:
refs/tags/v3.1.0 - Owner: https://github.com/EinMaulwurf
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@81d80a0ccff46e63fd65326deff0f5af7ec06bfc -
Trigger Event:
push
-
Statement type:
File details
Details for the file tytable-3.1.0-py3-none-any.whl.
File metadata
- Download URL: tytable-3.1.0-py3-none-any.whl
- Upload date:
- Size: 92.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
76e2495bdbe606425e2ab48b0db59597755280b6ee78eac6cbc2d1f023ad706e
|
|
| MD5 |
ee441a257ea60de969f82dc15e5be5f8
|
|
| BLAKE2b-256 |
7343b46445c7f00c1f552de787dbbd40d41c862ccb4cd190f13c4b496a83f159
|
Provenance
The following attestation bundles were made for tytable-3.1.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-3.1.0-py3-none-any.whl -
Subject digest:
76e2495bdbe606425e2ab48b0db59597755280b6ee78eac6cbc2d1f023ad706e - Sigstore transparency entry: 2729966409
- Sigstore integration time:
-
Permalink:
EinMaulwurf/tytable@81d80a0ccff46e63fd65326deff0f5af7ec06bfc -
Branch / Tag:
refs/tags/v3.1.0 - Owner: https://github.com/EinMaulwurf
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@81d80a0ccff46e63fd65326deff0f5af7ec06bfc -
Trigger Event:
push
-
Statement type: