Skip to content

Parser

omniread.csv.parser

Summary

CSV parser implementations for OmniRead.

This module provides a concrete, generic parser for comma-separated-value documents. It exposes records as lists of string cells so downstream consumers can interpret tabular content without depending on the csv module directly.

The parser is intentionally statement-agnostic: it performs no header detection or column interpretation beyond basic cell normalization and delimiter detection.

Classes

CsvParser

CsvParser(content: Content)

Bases: CsvParserBase[list[list[str]]]

Generic csv parser producing string rows from the document.

Notes

Responsibilities:

1
2
3
4
5
- Decode the payload (UTF-8 with BOM support, Latin-1 fallback).
- Detect the delimiter from a leading sample (`,` `;` tab `|`),
  defaulting to `,`.
- Normalize cells into deterministic stripped string values.
- Expose row extraction helpers mirroring `XlsxParser.rows`.

Constraints:

1
2
3
4
- All values are strings; consumers requiring typed values must
  convert on their side.
- Quoted fields containing delimiters/newlines are handled by
  the standard ``csv`` module.

Initialize the parser.

Parameters:

Name Type Description Default
content Content

CSV content to parse; its type must be supported.

required
Attributes
supported_types class-attribute instance-attribute
supported_types = {CSV}

Set of content types supported by this parser (CSV only).

Functions
parse
parse() -> list[list[str]]

Parse the document into normalized string rows.

Returns:

Type Description
list[list[str]]

List[List[str]]: Rows of the document.

rows
rows(*, skip_empty: bool = True) -> list[list[str]]

Extract normalized string rows from the document.

Parameters:

Name Type Description Default
skip_empty bool

When True (default), rows whose cells are all blank are omitted.

True

Returns:

Type Description
list[list[str]]

List[List[str]]: Normalized rows; trailing blank cells are trimmed per row.

supports
supports() -> bool

Check whether this parser supports the content's type.

Returns:

Name Type Description
bool bool

True if the content type is supported; False otherwise.