ZAGROS

Extensions

CSV (csv)

Parse CSV and TSV into rows or dicts, auto-detect the delimiter, and write rows back.

No permission is needed: these are pure functions. Generated from the tools registry.

3 functions. Use them as csv.<name>(...) in any extension.

csv.detect_delimiter #

csv.detect_delimiter(text: str) -> str

Guess the separator of delimited text: comma, semicolon, tab or pipe, chosen by how consistently each appears across the first lines. Returns a comma when nothing fits.

ParameterTypeDescription
textstrThe delimited text.

Returns str. Example: csv.detect_delimiter("a;b;c\n1;2;3")

Keywords: which delimiter, separator, sniff csv, csv, delimiter, sniff

csv.dump #

csv.dump(rows: Any, delimiter: str = ",", columns: List[str] = [], header: bool = True, crlf: bool = False) -> str

Write rows as CSV text. Rows are lists of values or dicts; for dicts the columns are the keys in first-seen order unless columns is given. Cells that need it are quoted. None becomes an empty cell. Raises when a cell is a list or dict.

ParameterTypeDescription
rowsAnyA list of lists, or a list of dicts.
delimiterstr (default ",")Single character separator (use \t for tab).
columnsList[str] (default [])Column order for dict rows; empty derives it from the rows.
headerbool (default True)Write a header line when rows are dicts or columns is set.
crlfbool (default False)End lines with CRLF instead of LF.

Returns str. Example: csv.dump([{"name": "ada", "age": 36}, {"name": "bob", "age": 41}])

Keywords: list to csv, table to csv, export csv, tsv output, rows to text, dicts to csv, csv, tsv, write, export, table, rows

csv.parse #

csv.parse(text: str, delimiter: str = "", header: bool = False, trim: bool = False, comment: str = "", strict: bool = False) -> Any

Parse CSV or TSV text. Returns a list of rows (lists of strings), or with header=True a list of dicts keyed by the first row. An empty delimiter detects comma, semicolon, tab or pipe from the first lines. Quotes may be loose unless strict=True. A UTF-8 BOM is dropped. Raises on malformed quoting in strict mode.

ParameterTypeDescription
textstrThe CSV text.
delimiterstr (default "")Single character separator (use \t for tab); empty detects it.
headerbool (default False)Use the first row as keys and return dicts.
trimbool (default False)Trim spaces around each cell.
commentstr (default "")A character that starts a comment line to skip; empty keeps all lines.
strictbool (default False)Reject bare quotes inside unquoted cells.

Returns Any. Example: csv.parse("name,age\nada,36\nbob,41", header=True)

Keywords: csv to list, tsv, spreadsheet, read table, split columns, comma separated, parse delimited text, rows to dicts, csv, parse, table, rows, delimiter

Edit this page on GitHub