Skip to main content

bambootex

Convert pandas DataFrames into LaTeX/PDF tables using tabularray.

Requirements

  • Python >= 3.11
  • A TeX distribution with pdflatex (e.g. TeX Live)
  • The following LaTeX packages: tabularray, siunitx, xcolor, babel, lmodern, fontenc

Installation

pip install bambootex

Quick start

import pandas as pd
from bambootex import Table, Cell, Font, Size, TextFormatter, GradientHighlighter, SimpleHighlighter

df = pd.read_csv("iris.csv")

tbl = Table(
    df,
    columns=["species", "sepal_length", "sepal_width"],
    column_formatters={
        "species": TextFormatter(font=Font.sf, size=Size.small),
    },
    headers=[
        [Cell("Species", vspan=2), Cell("Sepal", hspan=2)],
        [Cell(""), Cell("Length"), Cell("Width")],
    ],
    packages=["libertine"],
)

tbl.sort_by("sepal_length")
tbl.highlight("sepal_length", GradientHighlighter("white", "red"))
tbl.to_pdf("output.pdf")

API

Table

Table(
    df,                      # pd.DataFrame
    columns,                 # columns to include, in order
    column_formatters=None,  # dict of column -> format string, NumberFormatter, or TextFormatter
    headers=None,            # list of header rows, each a list of Cell
    packages=None,           # extra LaTeX packages to load
    number_format=".2f",     # default format for float columns (str or NumberFormatter)
    vlines=None,             # list of column indices to draw a vertical line after
    hlines=None,             # list of row indices to draw a horizontal line after
    default_size=None,       # document-wide font size (str or Size)
    merge_rows=None,         # column names whose consecutive equal values are merged into a row-spanning cell
)

Merging repeated cells vertically (merge_rows)

Consecutive rows with equal values in a merge_rows column are rendered as a single, vertically-centered, row-spanning cell instead of repeating the value on every row. This composes with .highlight(...): the merged cell's background is taken from the group's first row.

tbl = Table(
    df,
    columns=["dataset", "tool", "success"],
    merge_rows=["dataset"],
)

For finer control (e.g. spanning only some groups, or spanning multiple columns per cell), a column_formatters entry may return a Cell directly instead of a string — _build_content honors Cell.vspan/Cell.hspan the same way header cells do, covering the following rows/columns automatically.

.sort_by(key, reverse=False)

Sort rows before rendering. key can be a column name, list of column names, or a row-wise callable.

.highlight(column, highlighter, *fns)

Highlight cells in one or more columns.

  • Single column (column: str): filter functions receive the full column series.
  • Multiple columns (column: list[str]): a single predicate (value, row_subset) -> bool selects which cells to highlight per row.
# Gradient across all rows
tbl.highlight("score", GradientHighlighter("white", "red"))

# Highlight minimum per row across columns
tbl.highlight(
    ["time_a", "time_b", "time_c"],
    SimpleHighlighter("green!25"),
    lambda v, row: v == row.min(),
)

.to_tex(output_path) / .to_pdf(output_path)

Render to a .tex file or compile directly to PDF (requires pdflatex on $PATH).


Cell

Defines a header or body cell (see merge_rows above for body usage).

Cell(
    text,        # cell content
    hspan=1,     # columns to span
    vspan=1,     # rows to span
    align="c",   # tabularray halign: "l", "c", or "r"
    font=None,   # LaTeX font command, e.g. Font.tt or r"\texttt"
    valign=None, # tabularray valign: "t", "m", "b", "h", or "f"
    bg=None,     # xcolor color name to fill the cell background
)

TextFormatter

Applies LaTeX styling to a column's string values. When align is set, it also controls the column's alignment in the colspec.

TextFormatter(
    font=Font.sf,       # font command or list of font commands
    size=Size.small,    # size command
    align="c",          # column alignment ("l", "c", "r")
    prefix="(",         # prepended to each value
    suffix=")",         # appended to each value
)

NumberFormatter

Controls formatting of numeric columns.

NumberFormatter(
    decimal_places=2,   # decimal places
    unit=None,          # unit string appended after value
    nan=None,           # string to substitute for NaN values (e.g. "--")
)

Font

Font.rm   # \textrm
Font.sf   # \textsf
Font.tt   # \texttt
Font.bf   # \textbf
Font.it   # \textit

Size

Size.tiny / Size.scriptsize / Size.footnotesize / Size.small / Size.normalsize
Size.large / Size.Large / Size.LARGE / Size.huge / Size.Huge

Highlighters

Class Args Effect
SimpleHighlighter color Fills matching cells with a flat xcolor color
GradientHighlighter color_min, color_max Interpolates between two colors based on relative value

Any callable matching (series: pd.Series) -> dict[index, color_str] also works as a highlighter.

Metadata

Release files for bambootex 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bambootex 0.1.2
File Size Uploaded Provenance
bambootex-0.1.2.tar.gz 140.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for bambootex 0.1.2
File Interpreter ABI Platform
bambootex-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 149.1 kB

Release files / bambootex-0.1.2.tar.gz

Download URL bambootex-0.1.2.tar.gz
Size 140.8 kB
Tags Source
SHA-256 checksum
How to use checksums
5d0a975d8d791a397640b592579b8c2ea2ec9e03b53e01efa8ab3ba4a6ea91ae
BLAKE2b-256 checksum
How to use checksums
0a349fc7992ff11bd5564603f4078217c86ae60e6658cf3a79fd1f9f7f641b75
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / bambootex-0.1.2-py3-none-any.whl

Download URL bambootex-0.1.2-py3-none-any.whl
Size 8.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cd00a20858cf678d6df141292e0fd4d128646c118a664398da2c26e91ee27e4f
BLAKE2b-256 checksum
How to use checksums
5ff7dabecf09a4f9984b64279a0b6288774dcf1a8d0a71f27ccf097c1c8a0cf7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Security for bambootex 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page