Skip to main content

GT.as_gridwell()

Output a GT object as gridwell IR.

Usage

Source

GT.as_gridwell()

The as_gridwell() method outputs a GT object as the IR of gridwell, a JSON document that gridwell renders to HTML, LaTeX, Typst, RTF, SVG, Word, Excel, PowerPoint and other formats. The IR is IR 1.0, and the same table always gives the same JSON. Great Tables doesn’t need gridwell to write it.

Warning

as_gridwell() is still experimental, until gridwell’s IR 1.0 is frozen.

Returns

str
The table’s gridwell IR, as a JSON string.

Examples

The IR is a JSON string. Here it’s read back with json.loads(), to see the parts of the table it describes, and the header’s title.

import json
from great_tables import GT, exibble

gt_tbl = GT(exibble[["num", "char"]].head(3)).tab_header(title="A small table")

ir = json.loads(gt_tbl.as_gridwell())

list(ir), ir["header"]["title"]
(['ir_version',
  'config',
  'styles',
  'header',
  'column_spec',
  'table',
  'footer',
  'extensions'],
 {'content': [{'type': 'text', 'value': 'A small table'}], 'style_id': None})

gridwell reads the IR and renders it (here, as Typst). To save a table to one of gridwell’s formats in one step, use gtsave() with that format’s file extension.

from great_tables import GT, exibble
import gridwell

ir = GT(exibble).as_gridwell()
gridwell.parse_ir(ir).render_typst()