GT Integration Demo
The whole pipeline: a table made with Great Tables in Python, turned into gridwell IR, and rendered by gridwell’s writers.
Python code
from great_tables import GT, exibble
import gridwell
gt = (
GT(
exibble[["row", "group", "char", "num", "currency"]],
rowname_col="row",
groupname_col="group",
id="groups_and_stub",
)
.fmt_number(columns="num", decimals=2)
.fmt_currency(columns="currency", currency="USD")
)
table = gridwell.Table(gt) # the table as gridwell IR
assert table.validate() == []
print(table.render("latex"))This is the groups_and_stub case of the conformance kit, and the IR below is the one checked in for it, which the Python tests keep current.
NoteThe IR:
harness/gt-reference-py/groups_and_stub.ir.json
{
"ir_version": "1.0",
"config": {
"table_cols": 4,
"header_rows": 1,
"body_rows": 8,
"stub_cols": 1,
"row_striping": false,
"row_striping_include_stub": false,
"row_striping_include_body": false,
"column_labels_hidden": false,
"table_width": null,
"container_width": null,
"container_height": null,
"container_overflow": null,
"locale": "en-US",
"page_break_mode": "avoid",
"aria_label": null,
"aria_describedby": null,
"summary": null,
"id": "groups_and_stub"
},
"styles": {
"defs": {},
"compositions": {},
"conditionals": []
},
"header": {
"title": null,
"subtitle": null,
"extra_lines": [],
"preheader_content": null
},
"column_spec": [
{
"id": "row",
"align": "left",
"align_char": null,
"width": "auto",
"min_width": null,
"max_width": null,
"style_id": null,
"hidden": false,
"label": "row"
},
{
"id": "char",
"align": "left",
"align_char": null,
"width": "auto",
"min_width": null,
"max_width": null,
"style_id": null,
"hidden": false,
"label": "char"
},
{
"id": "num",
"align": "right",
"align_char": null,
"width": "auto",
"min_width": null,
"max_width": null,
"style_id": null,
"hidden": false,
"label": "num"
},
{
"id": "currency",
"align": "right",
"align_char": null,
"width": "auto",
"min_width": null,
"max_width": null,
"style_id": null,
"hidden": false,
"label": "currency"
}
],
"table": {
"thead": {
"rows": [
{
"role": "column_label",
"style_id": null,
"cells": [
{
"content": [],
"colspan": 1,
"rowspan": 1,
"style_id": null,
"is_stub": false,
"is_placeholder": false,
"scope": "col"
},
{
"content": [
{
"type": "text",
"value": "char"
}
],
"colspan": 1,
"rowspan": 1,
"style_id": null,
"is_stub": false,
"is_placeholder": false,
"scope": "col"
},
{
"content": [
{
"type": "text",
"value": "num"
}
],
"colspan": 1,
"rowspan": 1,
"style_id": null,
"is_stub": false,
"is_placeholder": false,
"scope": "col"
},
{
"content": [
{
"type": "text",
"value": "currency"
}
],
"colspan": 1,
"rowspan": 1,
"style_id": null,
"is_stub": false,
"is_placeholder": false,
"scope": "col"
}
]
}
]
},
"tbody": [
{
"group_id": "grp_a",
"label": {
"content": [
{
"type": "text",
"value": "grp_a"
}
],
"style_id": null,
"colspan": null
},
"rows": [
{
"role": null,
"style_id": null,
"cells": [
{
"content": [
{
"type": "text",
"value": "row_1"
}
],
"colspan": 1,
"rowspan": 1,
"style_id": null,
"is_stub": true,
"is_placeholder": false,
"scope": "row"
},
{
"content": [
{
"type": "text",
"value": "apricot"
}
],
"colspan": 1,
"rowspan": 1,
"style_id": null,
"is_stub": false,
"is_placeholder": false,
"typed_value": {
"type": "string",
"value": "apricot"
}
},
{
"content": [
{
"type": "text",
"value": "0.11"
}
],
"colspan": 1,
"rowspan": 1,
"style_id": null,
"is_stub": false,
"is_placeholder": false,
"typed_value": {
"type": "number",
"value": 0.11
}
},
{
"content": [
{
"type": "text",
"value": "$49.95"
}
],
"colspan": 1,
"rowspan": 1,
"style_id": null,
"is_stub": false,
"is_placeholder": false,
"typed_value": {
"type": "number",
"value": 49.95
}
}
]
},
{
"role": null,
"style_id": null,
"cells": [
{
"content": [
{
"type": "text",
"value": "row_2"
}
],
"colspan": 1,
"rowspan": 1,
"style_id": null,
"is_stub": true,
"is_placeholder": false,
"scope": "row"
},
{
"content": [
{
"type": "text",
"value": "banana"
}
],
"colspan": 1,
"rowspan": 1,
"style_id": null,
"is_stub": false,
"is_placeholder": false,
"typed_value": {
"type": "string",
"value": "banana"
}
},
{
"content": [
{
"type": "text",
"value": "2.22"
}
],
"colspan": 1,
"rowspan": 1,
"style_id": null,
"is_stub": false,
"is_placeholder": false,
"typed_value": {
"type": "number",
"value": 2.22
}
},
{
"content": [
{
"type": "text",
"value": "$17.95"
}
],
"colspan": 1,
"rowspan": 1,
"style_id": null,
"is_stub": false,
"is_placeholder": false,
"typed_value": {
"type": "number",
"value": 17.95
}
}
]
},
{
"role": null,
"style_id": null,
"cells": [
{
"content": [
{
"type": "text",
"value": "row_3"
}
],
"colspan": 1,
"rowspan": 1,
"style_id": null,
"is_stub": true,
"is_placeholder": false,
"scope": "row"
},
{
"content": [
{
"type": "text",
"value": "coconut"
}
],
"colspan": 1,
"rowspan": 1,
"style_id": null,
"is_stub": false,
"is_placeholder": false,
"typed_value": {
"type": "string",
"value": "coconut"
}
},
{
"content": [
{
"type": "text",
"value": "33.33"
}
],
"colspan": 1,
"rowspan": 1,
"style_id": null,
"is_stub": false,
"is_placeholder": false,
"typed_value": {
"type": "number",
"value": 33.33
}
},
{
"content": [
{
"type": "text",
"value": "$1.39"
}
],
"colspan": 1,
"rowspan": 1,
"style_id": null,
"is_stub": false,
"is_placeholder": false,
"typed_value": {
"type": "number",
"value": 1.39
}
}
]
},
{
"role": null,
"style_id": null,
"cells": [
{
"content": [
{
"type": "text",
"value": "row_4"
}
],
"colspan": 1,
"rowspan": 1,
"style_id": null,
"is_stub": true,
"is_placeholder": false,
"scope": "row"
},
{
"content": [
{
"type": "text",
"value": "durian"
}
],
"colspan": 1,
"rowspan": 1,
"style_id": null,
"is_stub": false,
"is_placeholder": false,
"typed_value": {
"type": "string",
"value": "durian"
}
},
{
"content": [
{
"type": "text",
"value": "444.40"
}
],
"colspan": 1,
"rowspan": 1,
"style_id": null,
"is_stub": false,
"is_placeholder": false,
"typed_value": {
"type": "number",
"value": 444.4
}
},
{
"content": [
{
"type": "text",
"value": "$65,100.00"
}
],
"colspan": 1,
"rowspan": 1,
"style_id": null,
"is_stub": false,
"is_placeholder": false,
"typed_value": {
"type": "number",
"value": 65100.0
}
}
]
}
],
"summary_rows": []
},
{
"group_id": "grp_b",
"label": {
"content": [
{
"type": "text",
"value": "grp_b"
}
],
"style_id": null,
"colspan": null
},
"rows": [
{
"role": null,
"style_id": null,
"cells": [
{
"content": [
{
"type": "text",
"value": "row_5"
}
],
"colspan": 1,
"rowspan": 1,
"style_id": null,
"is_stub": true,
"is_placeholder": false,
"scope": "row"
},
{
"content": [
{
"type": "text",
"value": "None"
}
],
"colspan": 1,
"rowspan": 1,
"style_id": null,
"is_stub": false,
"is_placeholder": false
},
{
"content": [
{
"type": "text",
"value": "5,550.00"
}
],
"colspan": 1,
"rowspan": 1,
"style_id": null,
"is_stub": false,
"is_placeholder": false,
"typed_value": {
"type": "number",
"value": 5550.0
}
},
{
"content": [
{
"type": "text",
"value": "$1,325.81"
}
],
"colspan": 1,
"rowspan": 1,
"style_id": null,
"is_stub": false,
"is_placeholder": false,
"typed_value": {
"type": "number",
"value": 1325.81
}
}
]
},
{
"role": null,
"style_id": null,
"cells": [
{
"content": [
{
"type": "text",
"value": "row_6"
}
],
"colspan": 1,
"rowspan": 1,
"style_id": null,
"is_stub": true,
"is_placeholder": false,
"scope": "row"
},
{
"content": [
{
"type": "text",
"value": "fig"
}
],
"colspan": 1,
"rowspan": 1,
"style_id": null,
"is_stub": false,
"is_placeholder": false,
"typed_value": {
"type": "string",
"value": "fig"
}
},
{
"content": [
{
"type": "text",
"value": "None"
}
],
"colspan": 1,
"rowspan": 1,
"style_id": null,
"is_stub": false,
"is_placeholder": false
},
{
"content": [
{
"type": "text",
"value": "$13.26"
}
],
"colspan": 1,
"rowspan": 1,
"style_id": null,
"is_stub": false,
"is_placeholder": false,
"typed_value": {
"type": "number",
"value": 13.26
}
}
]
},
{
"role": null,
"style_id": null,
"cells": [
{
"content": [
{
"type": "text",
"value": "row_7"
}
],
"colspan": 1,
"rowspan": 1,
"style_id": null,
"is_stub": true,
"is_placeholder": false,
"scope": "row"
},
{
"content": [
{
"type": "text",
"value": "grapefruit"
}
],
"colspan": 1,
"rowspan": 1,
"style_id": null,
"is_stub": false,
"is_placeholder": false,
"typed_value": {
"type": "string",
"value": "grapefruit"
}
},
{
"content": [
{
"type": "text",
"value": "777,000.00"
}
],
"colspan": 1,
"rowspan": 1,
"style_id": null,
"is_stub": false,
"is_placeholder": false,
"typed_value": {
"type": "number",
"value": 777000.0
}
},
{
"content": [
{
"type": "text",
"value": "None"
}
],
"colspan": 1,
"rowspan": 1,
"style_id": null,
"is_stub": false,
"is_placeholder": false
}
]
},
{
"role": null,
"style_id": null,
"cells": [
{
"content": [
{
"type": "text",
"value": "row_8"
}
],
"colspan": 1,
"rowspan": 1,
"style_id": null,
"is_stub": true,
"is_placeholder": false,
"scope": "row"
},
{
"content": [
{
"type": "text",
"value": "honeydew"
}
],
"colspan": 1,
"rowspan": 1,
"style_id": null,
"is_stub": false,
"is_placeholder": false,
"typed_value": {
"type": "string",
"value": "honeydew"
}
},
{
"content": [
{
"type": "text",
"value": "8,880,000.00"
}
],
"colspan": 1,
"rowspan": 1,
"style_id": null,
"is_stub": false,
"is_placeholder": false,
"typed_value": {
"type": "number",
"value": 8880000.0
}
},
{
"content": [
{
"type": "text",
"value": "$0.44"
}
],
"colspan": 1,
"rowspan": 1,
"style_id": null,
"is_stub": false,
"is_placeholder": false,
"typed_value": {
"type": "number",
"value": 0.44
}
}
]
}
],
"summary_rows": []
}
]
},
"footer": {
"footnotes": [],
"source_notes": []
},
"extensions": {}
}Outputs
Every tab but “Great Tables” is the real output of gridwell convert for that IR, which the docs’ tests check. “Great Tables” is Great Tables’ own HTML for the same table (as_raw_html()), to compare with gridwell’s Preview. The HTML tab shows the markup without the base stylesheet ("base_styles": false); the ANSI tab is drawn without color.
| char | num | currency | |
|---|---|---|---|
| grp_a | |||
| row_1 | apricot | 0.11 | $49.95 |
| row_2 | banana | 2.22 | $17.95 |
| row_3 | coconut | 33.33 | $1.39 |
| row_4 | durian | 444.40 | $65,100.00 |
| grp_b | |||
| row_5 | None | 5,550.00 | $1,325.81 |
| row_6 | fig | None | $13.26 |
| row_7 | grapefruit | 777,000.00 | None |
| row_8 | honeydew | 8,880,000.00 | $0.44 |
| char | num | currency | |
|---|---|---|---|
| grp_a | |||
| row_1 | apricot | 0.11 | $49.95 |
| row_2 | banana | 2.22 | $17.95 |
| row_3 | coconut | 33.33 | $1.39 |
| row_4 | durian | 444.40 | $65,100.00 |
| grp_b | |||
| row_5 | None | 5,550.00 | $1,325.81 |
| row_6 | fig | None | $13.26 |
| row_7 | grapefruit | 777,000.00 | None |
| row_8 | honeydew | 8,880,000.00 | $0.44 |
<div id="groups_and_stub" class="gw_container">
<style>
#groups_and_stub .gw_table .gw__al_left { text-align: left }
#groups_and_stub .gw_table .gw__al_right { text-align: right }
</style>
<table class="gw_table">
<thead>
<tr class="gw_col_labels">
<th class="gw_stubhead gw__al_left" scope="col"></th>
<th class="gw_col_label gw__al_left" scope="col" id="groups_and_stub-char">char</th>
<th class="gw_col_label gw__al_right" scope="col" id="groups_and_stub-num">num</th>
<th class="gw_col_label gw__al_right" scope="col" id="groups_and_stub-currency">currency</th>
</tr>
</thead>
<tbody>
<tr>
<th colspan="4" scope="colgroup" class="gw_group_label gw__al_left" id="groups_and_stub-grp_a">
grp_a
</th>
</tr>
<tr>
<th class="gw_stub gw__al_left" scope="row" id="groups_and_stub-stub-1">row_1</th>
<td headers="groups_and_stub-grp_a groups_and_stub-stub-1 groups_and_stub-char">apricot</td>
<td class="gw__al_right" headers="groups_and_stub-grp_a groups_and_stub-stub-1 groups_and_stub-num">0.11</td>
<td class="gw__al_right" headers="groups_and_stub-grp_a groups_and_stub-stub-1 groups_and_stub-currency">$49.95</td>
</tr>
<tr>
<th class="gw_stub gw__al_left" scope="row" id="groups_and_stub-stub-2">row_2</th>
<td headers="groups_and_stub-grp_a groups_and_stub-stub-2 groups_and_stub-char">banana</td>
<td class="gw__al_right" headers="groups_and_stub-grp_a groups_and_stub-stub-2 groups_and_stub-num">2.22</td>
<td class="gw__al_right" headers="groups_and_stub-grp_a groups_and_stub-stub-2 groups_and_stub-currency">$17.95</td>
</tr>
<tr>
<th class="gw_stub gw__al_left" scope="row" id="groups_and_stub-stub-3">row_3</th>
<td headers="groups_and_stub-grp_a groups_and_stub-stub-3 groups_and_stub-char">coconut</td>
<td class="gw__al_right" headers="groups_and_stub-grp_a groups_and_stub-stub-3 groups_and_stub-num">33.33</td>
<td class="gw__al_right" headers="groups_and_stub-grp_a groups_and_stub-stub-3 groups_and_stub-currency">$1.39</td>
</tr>
<tr>
<th class="gw_stub gw__al_left" scope="row" id="groups_and_stub-stub-4">row_4</th>
<td headers="groups_and_stub-grp_a groups_and_stub-stub-4 groups_and_stub-char">durian</td>
<td class="gw__al_right" headers="groups_and_stub-grp_a groups_and_stub-stub-4 groups_and_stub-num">444.40</td>
<td class="gw__al_right" headers="groups_and_stub-grp_a groups_and_stub-stub-4 groups_and_stub-currency">$65,100.00</td>
</tr>
</tbody>
<tbody>
<tr>
<th colspan="4" scope="colgroup" class="gw_group_label gw__al_left" id="groups_and_stub-grp_b">
grp_b
</th>
</tr>
<tr>
<th class="gw_stub gw__al_left" scope="row" id="groups_and_stub-stub-5">row_5</th>
<td headers="groups_and_stub-grp_b groups_and_stub-stub-5 groups_and_stub-char">None</td>
<td class="gw__al_right" headers="groups_and_stub-grp_b groups_and_stub-stub-5 groups_and_stub-num">5,550.00</td>
<td class="gw__al_right" headers="groups_and_stub-grp_b groups_and_stub-stub-5 groups_and_stub-currency">$1,325.81</td>
</tr>
<tr>
<th class="gw_stub gw__al_left" scope="row" id="groups_and_stub-stub-6">row_6</th>
<td headers="groups_and_stub-grp_b groups_and_stub-stub-6 groups_and_stub-char">fig</td>
<td class="gw__al_right" headers="groups_and_stub-grp_b groups_and_stub-stub-6 groups_and_stub-num">None</td>
<td class="gw__al_right" headers="groups_and_stub-grp_b groups_and_stub-stub-6 groups_and_stub-currency">$13.26</td>
</tr>
<tr>
<th class="gw_stub gw__al_left" scope="row" id="groups_and_stub-stub-7">row_7</th>
<td headers="groups_and_stub-grp_b groups_and_stub-stub-7 groups_and_stub-char">grapefruit</td>
<td class="gw__al_right" headers="groups_and_stub-grp_b groups_and_stub-stub-7 groups_and_stub-num">777,000.00</td>
<td class="gw__al_right" headers="groups_and_stub-grp_b groups_and_stub-stub-7 groups_and_stub-currency">None</td>
</tr>
<tr>
<th class="gw_stub gw__al_left" scope="row" id="groups_and_stub-stub-8">row_8</th>
<td headers="groups_and_stub-grp_b groups_and_stub-stub-8 groups_and_stub-char">honeydew</td>
<td class="gw__al_right" headers="groups_and_stub-grp_b groups_and_stub-stub-8 groups_and_stub-num">8,880,000.00</td>
<td class="gw__al_right" headers="groups_and_stub-grp_b groups_and_stub-stub-8 groups_and_stub-currency">$0.44</td>
</tr>
</tbody>
</table>
</div>\begin{tabular}{llrr}
\toprule
& char & num & currency \\
\midrule
\multicolumn{4}{l}{\bfseries grp\_a} \\
\midrule
row\_1 & apricot & 0.11 & \$49.95 \\
row\_2 & banana & 2.22 & \$17.95 \\
row\_3 & coconut & 33.33 & \$1.39 \\
row\_4 & durian & 444.40 & \$65,100.00 \\
\midrule
\multicolumn{4}{l}{\bfseries grp\_b} \\
\midrule
row\_5 & None & 5,550.00 & \$1,325.81 \\
row\_6 & fig & None & \$13.26 \\
row\_7 & grapefruit & 777,000.00 & None \\
row\_8 & honeydew & 8,880,000.00 & \$0.44 \\
\bottomrule
\end{tabular}#block[
#set align(left)
#table(
columns: (auto, auto, auto, auto,),
align: (left, left, right, right,),
stroke: none,
table.header(
[],
[#text(weight: "bold")[char]],
[#text(weight: "bold")[num]],
[#text(weight: "bold")[currency]],
table.hline(stroke: 0.5pt),
),
table.hline(stroke: 0.5pt),
table.cell(colspan: 4, fill: luma(240))[#text(weight: "bold")[grp\_a]],
table.hline(stroke: 0.5pt),
[row\_1],
[apricot],
[0\.11],
[\$49\.95],
[row\_2],
[banana],
[2\.22],
[\$17\.95],
[row\_3],
[coconut],
[33\.33],
[\$1\.39],
[row\_4],
[durian],
[444\.40],
[\$65\,100\.00],
table.hline(stroke: 0.3pt),
table.hline(stroke: 0.5pt),
table.cell(colspan: 4, fill: luma(240))[#text(weight: "bold")[grp\_b]],
table.hline(stroke: 0.5pt),
[row\_5],
[None],
[5\,550\.00],
[\$1\,325\.81],
[row\_6],
[fig],
[None],
[\$13\.26],
[row\_7],
[grapefruit],
[777\,000\.00],
[None],
[row\_8],
[honeydew],
[8\,880\,000\.00],
[\$0\.44],
)
]┌────────────┬────────────┬──────────────┬────────────┐
│ │ char │ num │ currency │
├────────────┴────────────┴──────────────┴────────────┤
│ grp_a │
├────────────┬────────────┬──────────────┬────────────┤
│ row_1 │ apricot │ 0.11 │ $49.95 │
│ row_2 │ banana │ 2.22 │ $17.95 │
│ row_3 │ coconut │ 33.33 │ $1.39 │
│ row_4 │ durian │ 444.40 │ $65,100.00 │
├────────────┴────────────┴──────────────┴────────────┤
│ grp_b │
├────────────┬────────────┬──────────────┬────────────┤
│ row_5 │ None │ 5,550.00 │ $1,325.81 │
│ row_6 │ fig │ None │ $13.26 │
│ row_7 │ grapefruit │ 777,000.00 │ None │
│ row_8 │ honeydew │ 8,880,000.00 │ $0.44 │
└────────────┴────────────┴──────────────┴────────────┘