org.pycforge.csv · Author: PyCForge
License: GPL-3.0-only · Created: 2026-11-12
Runtime conversion · Direct declared calls
Bounded delimited-text readers and file-backed writers with explicit ownership and call signatures.
Use *import csv as records. Keep the caller-owned file open during use, with newline="" and encoding="utf-8". Reader rows compose with lists, dictionaries, JSON and lazy pipelines.
Runtime only. reader accepts an admitted iterable of Unicode strings; each item is a physical input line, optionally terminated with CR, LF or CRLF. Quoted fields may span items; no newline is inserted between unterminated items. Rows are fresh lists of strings. line_num counts consumed input items, including a malformed or non-string item. writer accepts only an existing Runtime text file; use newline="" and encoding="utf-8". writerow(row) accepts an admitted iterable of str, int64, finite float64, bool or None; None becomes an empty field. It returns the number of Unicode characters written. writerows(rows) processes rows in order and returns None. Both methods are positional-only. Delimiter and quotechar are distinct single ASCII characters other than NUL, CR or LF. Reader skipinitialspace and strict are bool; defaults are False. Writer lineterminator is CRLF (default) or LF. Quoting is minimal, quotes are doubled, and escaping is disabled. No dialect objects/registry, other formatting options, DictReader/DictWriter, Sniffer, field_size_limit, bytes, custom conversion hooks or writer callbacks. Malformed records raise catchable ValueError with input-item line and Unicode column; this bounded profile does not export csv.Error. Wrong value types raise TypeError. The reader discards a malformed partial row and may resume at the next input item; it never rewinds consumed input. EOF does not close or detach the source, so an underlying file can resume after seek. Constructors consume no records and perform no file writes. Readers and writers retain their input/file, share state through aliases, and never close caller-owned files. Keep with blocks open during use. Each writer row is formatted before writing; formatting errors write none of that row, but prior rows and partial I/O on device failure are not rolled back. A field is limited to 131072 Unicode scalars, a row to 16384 fields and a parsed input record or formatted output row to 1 MiB of UTF-8. Those format limits raise ValueError; configured Runtime work/allocation/depth exhaustion is fatal. Temporary buffers and partial output rows are released without rolling back allocations retained by inputs. Atomic helpers do not collect internally; live values require roots at collection boundaries. The existing Runtime defers collection while files are open. These are two reusable record kernels and their specified result interfaces, not arbitrary author-defined objects.
Initial reusable delimited-record profile.
Examples are author-supplied fixture snapshots. The SDK reports verification for its recorded environment; PyCForge registration does not rerun them.
Use *import csv in the module preamble. Each signature states accepted positions, names and defaults. A slash marks positional-only parameters; a star marks keyword-only parameters. Argument expansion, function values and Typed conversion are unsupported.
Runtime only. reader accepts an admitted iterable of Unicode strings; each item is a physical input line, optionally terminated with CR, LF or CRLF. Quoted fields may span items; no newline is inserted between unterminated items. Rows are fresh lists of strings. line_num counts consumed input items, including a malformed or non-string item. writer accepts only an existing Runtime text file; use newline="" and encoding="utf-8". writerow(row) accepts an admitted iterable of str, int64, finite float64, bool or None; None becomes an empty field. It returns the number of Unicode characters written. writerows(rows) processes rows in order and returns None. Both methods are positional-only. Delimiter and quotechar are distinct single ASCII characters other than NUL, CR or LF. Reader skipinitialspace and strict are bool; defaults are False. Writer lineterminator is CRLF (default) or LF. Quoting is minimal, quotes are doubled, and escaping is disabled. No dialect objects/registry, other formatting options, DictReader/DictWriter, Sniffer, field_size_limit, bytes, custom conversion hooks or writer callbacks. Malformed records raise catchable ValueError with input-item line and Unicode column; this bounded profile does not export csv.Error. Wrong value types raise TypeError. The reader discards a malformed partial row and may resume at the next input item; it never rewinds consumed input. EOF does not close or detach the source, so an underlying file can resume after seek. Constructors consume no records and perform no file writes. Readers and writers retain their input/file, share state through aliases, and never close caller-owned files. Keep with blocks open during use. Each writer row is formatted before writing; formatting errors write none of that row, but prior rows and partial I/O on device failure are not rolled back. A field is limited to 131072 Unicode scalars, a row to 16384 fields and a parsed input record or formatted output row to 1 MiB of UTF-8. Those format limits raise ValueError; configured Runtime work/allocation/depth exhaustion is fatal. Temporary buffers and partial output rows are released without rolling back allocations retained by inputs. Atomic helpers do not collect internally; live values require roots at collection boundaries. The existing Runtime defers collection while files are open. These are two reusable record kernels and their specified result interfaces, not arbitrary author-defined objects.
Parse delimited text lines into fresh string rows.
iterable: positional-only; required
delimiter: keyword-only; default ','
quotechar: keyword-only; default '"'
skipinitialspace: keyword-only; default False
strict: keyword-only; default False
Lazily parse fresh string rows; expose read-only line_num.
Construction consumes no input. Malformed rows raise ValueError with line and column; consumed input is not rewound. EOF retains the source.
Argument 1: Iterable of physical Unicode input lines; positional-only.
Argument 2: Single ASCII delimiter; keyword-only, default comma.
Argument 3: Single ASCII quote character; keyword-only, default double quote.
Argument 4: Skip spaces at a field start; keyword-only bool, default False.
Argument 5: Reject malformed closing quotes and incomplete quoted fields; keyword-only bool, default False.
Returns: A shared-state lazy reader of fresh string lists, with read-only line_num.
View example: record-roundtrip
Format rows into a retained text file.
file: positional-only; required
delimiter: keyword-only; default ','
quotechar: keyword-only; default '"'
lineterminator: keyword-only; default '\r\n'
Retain a text file and expose positional writerow(row) and writerows(rows).
writerow(row, /) returns characters written; writerows(rows, /) returns None. Fields admit strings, finite numbers, bool and None. Formatting completes before each row is written.
Argument 1: Existing Runtime text file; positional-only.
Argument 2: Single ASCII delimiter; keyword-only, default comma.
Argument 3: Single ASCII quote character; keyword-only, default double quote.
Argument 4: CRLF or LF; keyword-only, default CRLF.
Returns: A writer retaining the supplied file.
View example: record-roundtrip
Expected output is supplied by the author. Consult verification provenance for the checks performed; conversion-only SDK evidence does not test runtime behavior.
*import csv as records
def main():
reader = records.reader(['name,value\n', '"north,west",12\n', 'south,15\n'])
header = next(reader)
print(header, reader.line_num)
with open("records.csv", "w+", encoding="utf-8", newline="") as file:
writer = records.writer(file, delimiter=";", lineterminator="\n")
print(writer.writerow(header))
print(writer.writerows(reader))
file.seek(0)
print(file.read(), end="")
print(reader.line_num)
return 0
Expected standard output:
['name', 'value'] 1 11 None name;value north,west;12 south;15 3
Expected exit code: 0