CSV I/O API
Tier: Stable Core
Read and write Click Ladder CSV files.
laddercodec.read_csv
read_csv(
path: Path | str, *, strict: bool = True
) -> list[Rung]
Read any Click Ladder CSV and return one Rung per rung.
Handles both single-rung and multi-rung CSV files in a single call.
Each Rung is a dataclass with attributes logical_rows,
conditions, instructions, comment, comment_rtf::
rungs = read_csv(path)
r = rungs[0]
r.logical_rows # int
r.conditions # list[list[ConditionToken]]
r.instructions # list[AfToken]
r.comment # str | None
Returns the exact data needed for encode_rung().
Instruction tokens (e.g. X001, out(Y001)) are parsed into
Contact / Coil objects; wire tokens remain as strings.
When strict is False, unsupported AF instructions are silently
replaced with blank tokens instead of raising.
laddercodec.write_csv
write_csv(path: Path | str, rungs: list[Rung]) -> None
Write decoded rungs to a canonical CSV file.
Parameters
path:
Output file path.
rungs:
One or more decoded rungs (from decode_rung() or
decode_rungs()).
Raises
WriterError If any rung contains unknown instructions that cannot be serialized.