cadrumo.application.export.tabular module

Serialize tabular rows into TabularExportResult payloads.

Rows are rendered through the closed ExportSerializationFormat surface, with ExportFieldError and ExportFormatError preserving validation failures as structured application errors.

This module is a pure in-memory serializer. It returns bytes, media type, extension, field metadata, row count, and SHA-256 digest to the calling export service; it does not choose paths, write files, emit bucket events, or mutate canonical storage.

class ExportSerializationFormat(*values)[source]

Bases: StrEnum

Closed set of backend tabular export serialization formats.

CSV
JSONL
XLSX
class TabularExportResult(**data)[source]

Bases: BaseModel

Serialized tabular payload produced by serialize_tabular_rows().

The result carries the raw payload plus operator-facing metadata: ExportSerializationFormat, media type, filename extension, byte count, SHA-256 digest, row count, and normalized field names.

Parameters:

data (Any)

format: ExportSerializationFormat
media_type: str
filename_extension: str
payload: bytes
byte_size: NonNegativeInt
sha256: str
row_count: NonNegativeInt
fieldnames: tuple[str, ...]
serialize_tabular_rows(rows, *, fieldnames, export_format)[source]

Serialize string-keyed rows as deterministic CSV, JSON Lines, or XLSX.

Field order follows fieldnames and row order follows rows. Values are coerced to strings, missing fields become empty strings, and unknown fields raise ExportFieldError. Returns a TabularExportResult with encoded bytes, media type, filename extension, row count, field metadata, and payload digest.

Return type:

TabularExportResult

Parameters:
verify_export_metadata(*, payload, export_format, byte_size, sha256, media_type, filename_extension, row_count)[source]

Refuse export metadata that contradicts the payload it describes.

The single check behind every serialized-payload result. Each argument is a pure function of payload and export_format, so a value that disagrees with the bytes is false rather than merely different – and LedgerExportResult redeclares the same seven fields independently, which is exactly why the verification lives here once instead of at each declaration.

Raises:

ExportFieldError – A metadata value disagrees with the payload.

Return type:

None

Parameters: