Providers

A provider is responsible for supplying raw rows to xlea.

Built-in providers


Provider registry

Example — registering a custom CSV provider:

import csv
import xlea

class CSVProvider:
    def __init__(self, path, sheet=None):
        self._path = path

    def rows(self):
        with open(self._path, newline="") as f:
            yield from csv.reader(f)

xlea.register_provider(".csv", CSVProvider)

# xlea.autoread now handles .csv files
for row in xlea.autoread("report.csv", schema=MySchema):
    print(row)

Provider protocol

Any object that implements rows() -> Iterable[Iterable] is a valid provider — no base class required:

class xlea.providers.proto.ProviderProto(**kwargs)[source]

Bases: Protocol

Data provider protocol.

A provider is responsible for supplying raw tabular data as an iterable of rows. Each row itself must be an iterable of cell values.

Implementations may read from Excel files, CSV, databases or any other source.

Notes

Providers should not perform schema-specific logic.

Examples

Minimal provider:

class ListProvider:
    def rows(self):
        return [
            ("ID", "Name"),
            (1, "Alice"),
            (2, "Bob"),
        ]

Usage:

persons = read(ListProvider(), schema=Person)
rows()[source]
Return type:

Iterable[Iterable]