Skip to main content

Getting Started

Installation

Rust (as a library)

The crates aren’t on crates.io yet, so add the gridwell crate to your Cargo.toml from the repository:

[dependencies]
gridwell = { git = "https://github.com/rich-iannone/gridwell" }
# or only the formats you need:
# gridwell = { git = "https://github.com/rich-iannone/gridwell", default-features = false, features = ["html", "latex"] }

Each format is a cargo feature, all on by default.

Python

pip install gridwell          # Python 3.10+
pip install 'gridwell[gt]'    # include the Great Tables integration

R

# From a source package (needs Rust 1.85 or later):
install.packages("gridwell_0.1.0.tar.gz", repos = NULL, type = "source")

The source package carries the Rust crates it needs, so it builds offline. In a checkout of the repository, make it with cargo xtask r-source and then R CMD build target/r-source/gridwell.

CLI Tool

cargo install --locked --git https://github.com/rich-iannone/gridwell gridwell-cli

Or build from source:

git clone https://github.com/rich-iannone/gridwell.git
cd gridwell
cargo build --release -p gridwell-cli
# Binary at: target/release/gridwell

First Table

Create a table IR file called hello.json, with two columns and two rows:

hello.json
{
  "ir_version": "1.0",
  "config": { "table_cols": 2, "header_rows": 1, "body_rows": 2 },
  "styles": {},
  "column_spec": [
    { "id": "name", "align": "left" },
    { "id": "score", "align": "right" }
  ],
  "table": {
    "thead": {
      "rows": [
        {
          "role": "column_label",
          "cells": [
            { "content": [{ "type": "text", "value": "Name" }], "scope": "col" },
            { "content": [{ "type": "text", "value": "Score" }], "scope": "col" }
          ]
        }
      ]
    },
    "tbody": [
      {
        "rows": [
          {
            "cells": [
              { "content": [{ "type": "text", "value": "Alice" }] },
              {
                "content": [{ "type": "text", "value": "95" }],
                "typed_value": { "type": "number", "value": 95 }
              }
            ]
          },
          {
            "cells": [
              { "content": [{ "type": "text", "value": "Bob" }] },
              {
                "content": [{ "type": "text", "value": "87" }],
                "typed_value": { "type": "number", "value": 87 }
              }
            ]
          }
        ]
      }
    ]
  }
}

Every field it leaves out takes its default (see the IR schema). Then render it:

$ gridwell convert hello.json --to latex
\begin{tabular}{lr}
\toprule
Name & Score \\
\midrule
Alice & 95 \\
Bob & 87 \\
\bottomrule
\end{tabular}

or to another format, or a file:

gridwell convert hello.json --to html
gridwell convert hello.json --to typst
gridwell convert hello.json -o hello.docx

Using with Great Tables (Python)

from great_tables import GT, exibble
import gridwell

table = gridwell.Table(GT(exibble.head(3)))
html = table.render_html()
table  # in a notebook: the table itself; print(table) draws it as text

gridwell.Table() also takes IR as a JSON string or a dict.

Using with gt (R)

library(gt)
library(gridwell)

gt_tbl <- gt(exibble[1:3, ], rowname_col = "row", groupname_col = "group")
html <- gw_render_html(gt_tbl)      # every function takes a gt table
tbl <- as_gw_table(gt_tbl)          # or convert it once
tbl                                 # prints the table drawn as text

Every function also takes IR as a JSON string, or a gw_table from gw_parse_ir(). In R Markdown and Quarto, a gw_table a chunk returns is shown in the document’s own format: HTML, LaTeX (PDF) or Typst.