Render
render
Compact ToolResult text primitives (stdlib-strict).
Factored out of the duplicated _render.py copies that lived in
axm-backtest, axm-route and friends. Each AXM tool fills data (a
Pydantic model_dump) but often leaves text=None, so the MCP server falls
back to a verbose JSON dump. These primitives compose into a few-line métier
renderer that emits a compact, token-cheap text:
- :func:
header— the{tool} | {summary}first line. - :func:
labeled_block— a label followed by indented lines. - :func:
compact_table— an aligned columns table for homogeneous rows. - :func:
truncate— bounded text with a trailing ellipsis. - :func:
format_count/ :func:format_size— human-readable numbers. - :func:
render_result— a full compact, losslesstextwalker over an arbitrarydatapayload (never raises). - :func:
record_table— the lossless homogeneous-recordkey | keytable.
Strictly stdlib — no runtime dependency is added by importing this module.
compact_table(rows, headers=None)
Render rows as a column-aligned table, optionally with a headers row.
Tolerates ragged rows (short rows are padded) and arbitrarily wide cells.
None cells render as empty, never as the literal "None".
Source code in packages/axm-ingot/src/axm_ingot/render.py
format_count(n)
Render an item count, abbreviating thousands (1500 → '1.5K').
Source code in packages/axm-ingot/src/axm_ingot/render.py
format_size(num_bytes)
Render a byte count in human units (2048 → '2.0 KB').
Source code in packages/axm-ingot/src/axm_ingot/render.py
header(tool, summary)
Render the compact header line {tool} | {summary}.
header("audit", "3 findings") 'audit | 3 findings'
labeled_block(label, lines)
Render label followed by lines, each indented two spaces.
An empty lines yields an empty string so no dangling label is emitted.
None entries render as blank lines rather than the literal "None".
Source code in packages/axm-ingot/src/axm_ingot/render.py
record_table(rows, keys, *, indent=0)
Render a homogeneous dict list as key | key header + value rows.
Lossless: emits the shared keys once as a header line then one value row
per record. None cells render as an em-dash, bools as yes/no. indent
offsets every line by two spaces per level.
Source code in packages/axm-ingot/src/axm_ingot/render.py
render_result(tool, data, *, label='')
Render an arbitrary tool result as compact, lossless text.
Header is {tool} (plus | {label} when label is given); the body
preserves every field of data. A scalar-only payload collapses to the
arrow form {header} → {value}.
Never raises: any object — including an unrenderable or self-referential
one — yields a str (falling back to the header line on failure).
Source code in packages/axm-ingot/src/axm_ingot/render.py
truncate(text, limit)
Bound text to limit chars, appending an ellipsis when it overflows.
Text at or under limit is returned unchanged. The overflow result has at
most limit + 1 characters and ends with the ellipsis marker.