API reference¶
Public surface exported by isis_report_lib. Signatures and docstrings are
read from the installed package; run python scripts/gen_api_docs.py after
changing a public function or its docstring.
Primary API¶
agenerate_pdf¶
async def agenerate_pdf(payload: dict[str, Any] | isis_report_lib.models.ReportPayload, pdf_options: dict[str, Any] | None = None, template_dir: str | pathlib.Path | None = None, template_name: str = 'tabular.jinja', allowed_hosts: list[str] | None = None, limits: dict[str, int] | None = None) -> bytes
Generate a PDF (async) from a dict/ReportPayload payload.
Custom layouts: point template_dir at a directory with your own
.jinja files and pick one via template_name. Outbound http(s) is
denied by default; pass allowed_hosts (bare hostnames) to opt in.
limits is the operator quota cap (None = defaults, {} = off);
payload meta.limits may only tighten it.
generate_pdf¶
def generate_pdf(payload: dict[str, Any] | isis_report_lib.models.ReportPayload, pdf_options: dict[str, Any] | None = None, template_dir: str | pathlib.Path | None = None, template_name: str = 'tabular.jinja', allowed_hosts: list[str] | None = None, limits: dict[str, int] | None = None) -> bytes
Generate a PDF (sync) from a dict/ReportPayload payload.
agenerate_many¶
async def agenerate_many(payloads: list[dict[str, typing.Any] | isis_report_lib.models.ReportPayload], pdf_options: dict[str, Any] | None = None, max_concurrency: int = 4, template_dir: str | pathlib.Path | None = None, template_name: str = 'tabular.jinja', allowed_hosts: list[str] | None = None, limits: dict[str, int] | None = None) -> list[bytes]
Generate several PDFs concurrently, rejoining results in input order.
Pages share the browser pool; max_concurrency caps simultaneous pages.
For mixed options per report, use asyncio.gather over agenerate_pdf directly.
generate_many¶
def generate_many(payloads: list[dict[str, typing.Any] | isis_report_lib.models.ReportPayload], pdf_options: dict[str, Any] | None = None, max_concurrency: int = 4, template_dir: str | pathlib.Path | None = None, template_name: str = 'tabular.jinja', allowed_hosts: list[str] | None = None, limits: dict[str, int] | None = None) -> list[bytes]
Generate several PDFs concurrently (sync); results come back in input order.
agenerate_pdf_from_toon¶
async def agenerate_pdf_from_toon(text: str, pdf_options: dict[str, Any] | None = None, template_dir: str | pathlib.Path | None = None, template_name: str = 'tabular.jinja', allowed_hosts: list[str] | None = None, limits: dict[str, int] | None = None) -> bytes
Generate a PDF (async) from .toon text.
generate_pdf_from_toon¶
def generate_pdf_from_toon(text: str, pdf_options: dict[str, Any] | None = None, template_dir: str | pathlib.Path | None = None, template_name: str = 'tabular.jinja', allowed_hosts: list[str] | None = None, limits: dict[str, int] | None = None) -> bytes
Generate a PDF (sync) from .toon text.
agenerate_xlsx¶
async def agenerate_xlsx(payload: dict[str, Any] | isis_report_lib.models.ReportPayload, limits: dict[str, int] | None = None) -> bytes
Generate an .xlsx workbook (async, no browser needed).
generate_xlsx¶
def generate_xlsx(payload: dict[str, Any] | isis_report_lib.models.ReportPayload, limits: dict[str, int] | None = None) -> bytes
Generate an .xlsx workbook (sync, no browser needed).
agenerate_xlsx_from_toon¶
Generate an .xlsx workbook (async) from .toon text.
generate_xlsx_from_toon¶
Generate an .xlsx workbook (sync) from .toon text.
agenerate_csv¶
async def agenerate_csv(payload: dict[str, Any] | isis_report_lib.models.ReportPayload, delimiter: str = ',', bom: bool = False, limits: dict[str, int] | None = None) -> str
Generate CSV text (async, no browser needed).
bom=True prepends a UTF-8 BOM so Excel (PT) opens accented text correctly.
generate_csv¶
def generate_csv(payload: dict[str, Any] | isis_report_lib.models.ReportPayload, delimiter: str = ',', bom: bool = False, limits: dict[str, int] | None = None) -> str
Generate CSV text (sync, no browser needed).
agenerate_csv_from_toon¶
async def agenerate_csv_from_toon(text: str, delimiter: str = ',', bom: bool = False, limits: dict[str, int] | None = None) -> str
Generate CSV text (async) from .toon text.
generate_csv_from_toon¶
def generate_csv_from_toon(text: str, delimiter: str = ',', bom: bool = False, limits: dict[str, int] | None = None) -> str
Generate CSV text (sync) from .toon text.
arender_html¶
async def arender_html(payload: dict[str, Any] | isis_report_lib.models.ReportPayload, template_dir: str | pathlib.Path | None = None, template_name: str = 'tabular.jinja', inline_css: bool = False, limits: dict[str, int] | None = None) -> str
Render only the intermediate HTML (async, no Playwright).
render_html¶
def render_html(payload: dict[str, Any] | isis_report_lib.models.ReportPayload, template_dir: str | pathlib.Path | None = None, template_name: str = 'tabular.jinja', inline_css: bool = False, limits: dict[str, int] | None = None) -> str
Render only the intermediate HTML (sync, no Playwright).
render_html_from_toon¶
def render_html_from_toon(text: str, template_dir: str | pathlib.Path | None = None, template_name: str = 'tabular.jinja', inline_css: bool = False, limits: dict[str, int] | None = None) -> str
Render HTML (sync) from .toon text.
arender_text¶
async def arender_text(payload: dict[str, Any] | isis_report_lib.models.ReportPayload, *, sanitize: bool = True, limits: dict[str, int] | None = None) -> str
Render a visible-only, sanitized plain-text export (async, no browser).
Intended for LLM/RAG ingestion. Only fields visible in the report are
included (visible: false is dropped by the normal layout builder); the
text starts with a REPORT DATA preamble and end delimiter, and control,
format, surrogate and private-use characters are stripped by default.
Set sanitize=False only for exact debugging output.
render_text¶
def render_text(payload: dict[str, Any] | isis_report_lib.models.ReportPayload, *, sanitize: bool = True, limits: dict[str, int] | None = None) -> str
Render a visible-only, sanitized plain-text export (sync, no browser).
See arender_text for the safety properties and the data boundary.
arender_text_from_toon¶
async def arender_text_from_toon(text: str, *, sanitize: bool = True, limits: dict[str, int] | None = None) -> str
Render a visible-only, sanitized plain-text export (async) from .toon.
render_text_from_toon¶
def render_text_from_toon(text: str, *, sanitize: bool = True, limits: dict[str, int] | None = None) -> str
Render a visible-only, sanitized plain-text export (sync) from .toon.
Payload models¶
MetaInfo¶
class MetaInfo(*, title: str | None = None, sub_title: str | None = None, company: str | None = None, mode: str = 'exact', page: dict[str, Any] | None = None, locale: str | None = None, currency: str | None = None, accent_color: str | None = None, logo: str | None = None, watermark: Any = None, printed_at: Any = None, summary_side: Any = None, source_note: Any = None, empty_text: Any = None, limits: Any = None) -> None
Report metadata.
ReportPayload¶
class ReportPayload(*, meta: isis_report_lib.models.MetaInfo | None = None, layout: dict[str, Any] | None = None, data: list[typing.Any] = <factory>, sections: list[dict[str, Any]] | None = None) -> None
Report payload: metadata + optional hierarchical layout + data.
Layout and shaping¶
convert_layout¶
Convert the hierarchical layout into the render-ready format.
convert_data¶
def convert_data(data_raw: list[dict[str, typing.Any]], layout_raw: dict[str, typing.Any]) -> dict[str, typing.Any]
Convert raw data + raw layout into the template's {"groups": [...]}.
build_report¶
def build_report(data_raw: list[dict[str, typing.Any]], layout_raw: dict[str, typing.Any]) -> tuple[dict[str, typing.Any], dict[str, typing.Any]]
Build (dataset, layout) with parameters applied (filtering, sorting, totals).
Layout shape mirrors convert_layout with footer lists added wherever
aggregates are declared, plus top-level summary when declared there.
Every top-level record must be an object: a declared layout maps fields by name, so a scalar row cannot be rendered faithfully — fail closed instead of guessing (STANDARDS §2.3).
infer_layout¶
Infer a simple (header-only) layout from the first data row.
is_template_format¶
True when data is already in template format (records with fields).
template_header_layout¶
Header-only layout for data already in template format (records with fields).
Inputs¶
from_csv¶
def from_csv(source: str | pathlib.Path | Any, meta: dict[str, Any] | None = None, layout: dict[str, Any] | None = None, delimiter: str = ',', encoding: str = 'utf-8') -> dict[str, typing.Any]
Build a payload from a CSV file (path or file object) with light type coercion.
from_dataframe¶
def from_dataframe(df: Any, meta: dict[str, Any] | None = None, layout: dict[str, Any] | None = None) -> dict[str, typing.Any]
Build a payload from a pandas.DataFrame (columns become fields).
from_json¶
def from_json(source: str | pathlib.Path | Any, meta: dict[str, Any] | None = None, layout: dict[str, Any] | None = None, encoding: str = 'utf-8') -> dict[str, typing.Any]
Build a payload from JSON: a list becomes data; a full payload dict passes through.
payload_schema¶
Return the JSON Schema of the report payload (for editors and validation).
Formatting¶
format_value¶
def format_value(value: Any, format_mask: str, locale: str = 'pt-BR', currency: str | None = None, field: dict[str, Any] | None = None) -> str
Format a value according to the mask and locale.
Masks: str · int · float · percent (fraction, e.g. 0.09 → 9%) ·
currency · bool (Yes/No) · date (date/datetime objects are
localized; strings pass through) · sparkline (list of numbers → inline
SVG nanoplot; spark_kind line|bar and spark_color field options).
None → "".
field (the layout field definition) applies substitutions first,
then missing_text for None — see field_text. Templates pass
the current field; direct callers may omit it (previous behavior).
formatter_for¶
Build the fmt(value, mask) helper bound to the payload's locale/currency.
field_text¶
Mapped display text via substitutions/missing_text, else None.
substitutions maps raw values (exact match, then str(value) match)
to display strings; a None value with no substitution falls back to
missing_text (default: unmapped, i.e. None). Non-dict substitutions
is a schema error.
sparkline_text¶
Unicode block-art nanoplot ("" when there is no data).
Text-safe fallback for CSV/XLSX, where inline SVG cannot be embedded.
match_rule¶
Match a value against every comparison operator in the rule (AND).
Operators: equals · not_equals · in · not_in ·
gt · gte · lt · lte · between ([lo, hi],
inclusive) · contains (substring of the stringified value) ·
is_null · not_null. Style keys (color …) and unknown keys
are ignored here (cell_style_dict rejects the latter). A rule with
no comparison operator matches everything (catch-all default).
cell_style¶
First matching cell_rules entry as inline CSS ("" when none match).
A color_scale gradient fill applies when no rule set a background and
the field carries a computed color_domain (see layout).
cell_style_dict¶
First matching cell_rules entry as a style dict ({} when none match).
Rule form: {"gte": 1000, "lt": 5000, "color": "#C00000", "bold": True}
— all comparison operators in the rule must hold (AND); a rule with no
comparison operator is a catch-all default. Style keys are any of
color/background/bold/italic.
Exports (XLSX/CSV)¶
collect_tables¶
def collect_tables(dataset: dict[str, typing.Any], layout: dict[str, typing.Any], meta: dict[str, Any] | None = None) -> tuple[list[isis_report_lib.export.Table], list[tuple[str, typing.Any, str]]]
Flatten (dataset, layout) into tables plus (label, value, mask) summary rows.
Signing¶
SignatureInfo¶
class SignatureInfo(valid: bool, reason: str, alg: str | None = None, sha256: str | None = None, key_id: str | None = None, issued_at: str | None = None, details: dict[str, typing.Any] = <factory>) -> None
Verification outcome (valid plus machine-readable details).
HMAC_MIN_KEY_BYTES¶
Value: 32
int([x]) -> integer int(x, base=10) -> integer
Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.int(). For floating-point numbers, this truncates towards zero.
If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by '+' or '-' and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer iteral.
int('0b100', base=0) 4
generate_hmac_key¶
Generate a random shared secret for hmac-sha256 signatures (>=32 bytes).
generate_ed25519_keypair¶
Generate (private_pem, public_pem) for ed25519 signatures.
sign_pdf¶
def sign_pdf(pdf: bytes, key: bytes, *, alg: str = 'hmac-sha256', key_id: str | None = None, issued_at: str | None = None) -> bytes
Append a signature block to PDF bytes (original bytes are untouched).
key is the HMAC secret or the Ed25519 private key in PEM form.
Re-signing an already signed file is allowed (latest block wins).
verify_pdf¶
def verify_pdf(signed: bytes, key: bytes | dict[str, bytes] | list[bytes] | tuple[bytes, ...], *, alg: str = 'hmac-sha256') -> isis_report_lib.signing.SignatureInfo
Verify the latest signature block of a (possibly) signed PDF.
key is the HMAC secret or the Ed25519 public key in PEM form — or a
keyring for rotation: a {key_id: key} mapping (the envelope's
key_id selects first) or a key list (tried in order).
Never raises for malformed input — check .valid and .reason.
Service¶
BaseReportService¶
Defines the report lifecycle; execute enforces the step order.
execute¶
TabularReportService¶
class TabularReportService(pdf_options: dict[str, Any] | None = None, template_dir: str | pathlib.Path | None = None, template_name: str = 'tabular.jinja', allowed_hosts: list[str] | None = None, limits: dict[str, int] | None = None) -> None
Default tabular implementation of the pipeline.
execute¶
DEFAULT_LIMITS¶
Value: {'max_rows': 1000000, 'max_bytes': 67108864}
dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2)
.toon parser¶
ToonParser¶
Convert .toon text into a structured dict.
parse¶
Parse .toon text into a dict (dados accepted as legacy alias of data).
parse_toon¶
Functional shortcut: ToonParser().parse(text).
Crosstab¶
Crosstab¶
class Crosstab(row_headers: list[typing.Any] = <factory>, col_headers: list[typing.Any] = <factory>, cells: list[list[typing.Any]] = <factory>, row_totals: list[typing.Any] = <factory>, col_totals: list[typing.Any] = <factory>, grand_total: Any = '', totals: bool = True, row_label: str = '', col_label: str = '', total_label: str = 'Total', mask: str = 'str', measure_field: dict[str, typing.Any] = <factory>, row_field: dict[str, typing.Any] = <factory>, col_field: dict[str, typing.Any] = <factory>, empty_text: str = '') -> None
Normalized pivot: headers, raw cell values, totals and display defs.
build_crosstab¶
def build_crosstab(data: list[typing.Any], spec: dict[str, typing.Any]) -> isis_report_lib.crosstab.Crosstab
Build a crosstab from raw records and a rows/columns/measure spec.
Spec keys: rows, columns (field name or field def), measure
(field name or def; optional for count), function
(sum|count|avg|min|max), totals (default True),
total_label (default "Total"), empty_text.