Writing¶
Turn tables back into an 835. See Writing for the guide.
write ¶
write(
tables: TablesLike,
envelope: Envelope,
spec: Optional[Spec] = None,
allow_findings: Literal[False] = False,
) -> bytes
write(
tables: TablesLike,
envelope: Envelope,
spec: Optional[Spec] = None,
*,
allow_findings: Literal[True],
) -> tuple[bytes, list[WriteFinding]]
write(
tables: TablesLike,
envelope: Envelope,
spec: Optional[Spec] = None,
allow_findings: bool = False,
) -> Union[bytes, tuple[bytes, list[WriteFinding]]]
write(
tables: TablesLike,
envelope: Envelope,
spec: Optional[Spec] = None,
allow_findings: bool = False,
) -> Union[bytes, tuple[bytes, list[WriteFinding]]]
Writes tables with a spec's schema as one interchange.
tables is the tables of a parse, or a mapping of table names to
Arrow, Polars or pandas tables with the spec's columns (a table left out
has no rows, a column left out is null). spec defaults to the spec
that parsed the tables, else the built-in 5010 spec. The written file is
read back with the spec, and every diagnostic of that read is a finding.
A null cell in the middle of a segment is written as an empty element, which reads back as empty text; only trailing nulls read back as null.
Strict by default: any finding raises WriteError and nothing is
returned. With allow_findings the bytes are returned with the
findings, (bytes, findings). When a value holds a delimiter the file
is not read back, so the findings then lack those of reading it.
Envelope ¶
Who sends and receives an interchange, when, its first control number and its delimiters. The writer derives the rest of the envelope: counts, later control numbers, codes and fixed widths.
usage_indicator
property
¶
usage_indicator: str
The usage indicator, e.g. P (production) or T (test).
application_sender
property
¶
application_sender: Optional[str]
The functional group's sender code, when it is not the sender id.
application_receiver
property
¶
application_receiver: Optional[str]
The functional group's receiver code, when it is not the receiver id.
__new__ ¶
__new__(
*,
sender_id: str,
receiver_id: str,
date: date,
time: time,
sender_qualifier: str = "ZZ",
receiver_qualifier: str = "ZZ",
usage_indicator: str = "P",
control_number: int = 1,
application_sender: Optional[str] = None,
application_receiver: Optional[str] = None,
delimiters: Optional[Delimiters] = None,
line_break: bool = False,
) -> Envelope
date (a datetime.date) and time (a datetime.time without a
time zone, whole seconds) stamp the interchange and the group: the
interchange header holds the date without its century and the time
without its seconds, the group header keeps both. delimiters
defaults to *, :, ~ and the repetition separator ^;
line_break adds a line break after each segment.
WriteError ¶
Bases: ValueError
Tables that cannot be written as a valid file; nothing was written.
The message names every reason: the rule, where (table, row and column,
or envelope field) and the value. findings holds them one by one; it
is empty when the refusal is about the spec, the tables' columns or the
delimiters rather than about the data.