gamesheet_sdk.common.output¶
Multi-format rendering of tabular data for CLI workflows.
Every SDK workflow that produces a list of rows (associations, leagues, teams, …) flows through
render() to get a string. Supported formats fall into two groups. Data formats (machine-friendly,
not via tabulate): json, yaml, csv, tsv. Tabulate formats (human-readable or markup-
embeddable; every tablefmt value tabulate accepts): plain, simple, grid, fancy_grid,
pipe, orgtbl, rst, mediawiki, html, latex, latex_raw, latex_booktabs,
latex_longtable. The default format is simple. write_output() complements render() by
writing the rendered text to a file path (when one is given) or to stdout (with optional rich-driven
syntax highlighting when stdout is a TTY and the format is json or yaml).
Functions
|
Render |
|
Write |
- gamesheet_sdk.common.output.render(rows, fmt='simple', *, columns=None)[source]¶
Render
rowsas a string in the requested format.- Parameters:
- Returns:
Rendered string in the requested format.
- Return type:
- Raises:
ValueError – If
fmtis not inALL_FORMATS.
Example usage:
from gamesheet_sdk.common.output import render rows = [{"id": 123, "name": "Example"}, {"id": 456, "name": "Another"}] # Simple table format print(render(rows, fmt="simple")) # Output: # id name # --- ------- # 123 Example # 456 Another # JSON format print(render(rows, fmt="json")) # Output: # [ # { # "id": 123, # "name": "Example" # }, # { # "id": 456, # "name": "Another" # } # ] # CSV format print(render(rows, fmt="csv")) # Output: # id,name # 123,Example # 456,Another
- gamesheet_sdk.common.output.write_output(text, path, *, fmt)[source]¶
Write
texttopathor to stdout.When
pathisNoneand stdout is a TTY, JSON and YAML output is syntax-highlighted viarich.syntax.Syntax. Other formats and any non-TTY destination receivetextverbatim with a trailing newline if it does not already have one.File output example:
>>> from gamesheet_sdk.common.output import render, write_output >>> rows = [{"id": 123, "name": "Example"}] >>> text = render(rows, fmt="json") >>> write_output(text, "output.json", fmt="json") # Writes to output.json with trailing newline
TTY stdout example (JSON/YAML only):
>>> from gamesheet_sdk.common.output import write_output >>> write_output(text, None, fmt="json") # Syntax-highlighted output to terminal if stdout is a TTY
Non-TTY / other formats:
>>> from gamesheet_sdk.common.output import write_output >>> write_output(text, None, fmt="csv") # Plain text to stdout with trailing newline
- Parameters:
text (str) – Rendered output string to write.
path (str | Path | None) – Destination file path (str or
pathlib.Path), orNonefor stdout.fmt (str) – Format name (e.g.
"json","yaml","csv"); controls syntax highlighting on TTY stdout.