Csv
omniread.csv
Summary
CSV subpackage for OmniRead.
Provides acquisition and parsing of comma-separated-value content:
BaseCsvClient: abstract backing-store client for csv bytes.FileSystemCsvClient: local filesystem implementation.CsvScraper: wraps fetched bytes into canonicalContent.CsvParserBase: content-type-enforcing parser contract.CsvParser: generic string-row parser built on the standard csv module.
Classes
BaseCsvClient
Bases: ABC
Abstract client responsible for retrieving csv bytes.
Retrieves bytes from a specific backing store (filesystem, S3, FTP, etc.).
Notes
Responsibilities:
1 2 3 4 | |
Functions
fetch
abstractmethod
Fetch raw csv bytes from the given source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source |
Any
|
Identifier of the csv location, such as a file path, object storage key, or remote reference. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bytes |
bytes
|
Raw csv bytes. |
Raises:
| Type | Description |
|---|---|
Exception
|
Retrieval-specific errors defined by the implementation. |
CsvParser
Bases: CsvParserBase[list[list[str]]]
Generic csv parser producing string rows from the document.
Notes
Responsibilities:
1 2 3 4 5 | |
Constraints:
1 2 3 4 | |
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
Set of content types supported by this parser (CSV only).
Functions
parse
Parse the document into normalized string rows.
Returns:
| Type | Description |
|---|---|
list[list[str]]
|
list[list[str]]: Rows of the document. |
rows
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
Check whether this parser supports the content's type.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the content type is supported; False otherwise. |
CsvParserBase
Bases: BaseParser[T], Generic[T]
Base csv parser.
Notes
Responsibilities:
1 2 3 | |
Constraints:
1 2 | |
Initialize the parser with content to be parsed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content |
Content
|
Content instance to be parsed. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the content type is not supported by this parser. |
Attributes
supported_types
class-attribute
instance-attribute
Set of content types supported by this parser (CSV only).
Functions
parse
abstractmethod
Parse csv content into a structured output.
Returns:
| Name | Type | Description |
|---|---|---|
T |
T
|
Parsed representation of type |
Raises:
| Type | Description |
|---|---|
Exception
|
Parsing-specific errors as defined by the implementation. |
supports
Check whether this parser supports the content's type.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the content type is supported; False otherwise. |
CsvScraper
Scraper for csv documents.
Notes
Responsibilities:
1 2 3 | |
Constraints:
1 2 | |
Initialize the CSV scraper.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client |
BaseCsvClient
|
Client responsible for retrieving raw csv bytes. |
required |
Functions
fetch
Fetch a csv document from the given source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source |
Any
|
Identifier of the csv source as understood by the configured client. |
required |
metadata |
Mapping[str, Any] | None
|
Optional metadata to attach to the returned content. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Content |
Content
|
A |
Raises:
| Type | Description |
|---|---|
Exception
|
Retrieval-specific errors raised by the client. |
FileSystemCsvClient
Bases: BaseCsvClient
CSV client that reads from the local filesystem.
Notes
Guarantees:
1 2 | |
Functions
fetch
Read a csv file from the local filesystem.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path |
Path
|
Filesystem path to the csv file. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bytes |
bytes
|
Raw csv bytes. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the path does not exist. |
ValueError
|
If the path exists but is not a file. |