Repository navigation
First release. A second implementation of the
sr report format, in Python,
written from the specification rather than ported from the Go engine.
Engine
- Banded report engine with
title,summary,header,footer,
anddetailbands. - Group scoping, keep-together, orphan/widow control, balanced columns.
- Deferred evaluation, so the first page can print the final page count.
- Running variables with twelve
calcmodes for data aggregation.
Templates and data
- KDL v2 templates.
- A node or property the format does not define is accepted with a warning,
and is an error when it is one edit from a legal name. Anacceptnode,
--accept, or anx-prefix accepts a name without a warning;
--strict-namesmakes every other unknown name an error. - JSON or NDJSON input in UTF-8, with field types declared in the template.
- Sandboxed Starlark expressions:
no imports, no filesystem, no network. - Typed report parameters, with defaults and default expressions.
- Subreports, from an
embeddedlayout in the same template or from
a separate file named bytemplate=. Either kind prints inline
in the host's frame or on pages of its own; a separate file can
give those pages a geometry of their own. - Embedded and referenced images, with relative paths in printouts.
- Seven barcode types, encoded here from the standards: Code 128, Code 39,
Code 93, Interleaved 2 of 5, QR, Data Matrix, and Aztec.
Printout and renderer
- Printout: a renderer-neutral, absolutely-positioned, archive-friendly
document, written as NDJSON or CBOR. - Same printout round-trips to a byte-identical PDF.
- Printout embeds images and data blobs, fonts given by
data=included.
Fonts and images the template names by path are written relative to
the printout, so a printout and those files move as one tree.
A font found on the host is written as an absolute path. - Every printout is checked against its twelve invariants before it is
written, ands-reports inspectchecks any printout it reads. - PDF output with no layout decisions of its own.
- Reproducible: same template + same data +
--build-time+--strict-fonts
produce same bytes on any machine.
Command line
s-reports build,s-reports validate,s-reports render,
s-reports inspect,s-reports version,s-reports help.- The same program runs as
python -m sr, and aspython sr.py
in a checkout without installing the package. - Document on stdout, diagnostics on stderr, three exit codes.
- Both streams are UTF-8 with LF line endings on every platform,
Windows included.
Library
sr.apifor the engine,sr.printoutfor the document a renderer reads,
sr.pdffor the renderer. Fully typed, withpy.typed.- Python 3.11 to 3.14, tested on Linux, macOS, and Windows.
- Five dependencies: ckdl, fontTools, cbor2, Pillow, and tzdata.
The expression evaluator, the barcode encoders, the layout,
and the PDF writer are written here.
Compared with the Go engine
- The test suite builds the examples and a corpus of probes with both
engines, and compares the printouts byte for byte, the PDFs pixel
by pixel, and the command line's reports line by line. - The 65 differences are listed in
divergences.toml,
each with its reason, and with the section ofdoc/that settles it
where there is one. 40 of them are filed against the Go engine.
Documentation
- The template format, the expression environment, layout and pagination,
the printout format, barcode encoding, PDF rendering, and the command line
are each specified in doc/.
This is the Go project's specification, with the questions it left
to the code answered, and barcode encoding added. - Three worked examples.
minimal
is the printout doc/printout.md prints,
built and compared byte for byte by the tests.
sakila
and invoices
between them use every node in the format butaccept, and all
twelvecalcmodes.