From 14d89f5f91ec53c7e3bf788685ceda008ff5ac48 Mon Sep 17 00:00:00 2001 From: Vishesh 'ironeagle' Bangotra Date: Sat, 12 Sep 2026 15:26:30 +0530 Subject: [PATCH] feat: add type stubs for csv and xlsx subpackages --- omniread/csv/__init__.pyi | 12 ++++++++++++ omniread/csv/client.pyi | 10 ++++++++++ omniread/csv/parser.pyi | 8 ++++++++ omniread/csv/parser_base.pyi | 13 +++++++++++++ omniread/csv/scraper.pyi | 12 ++++++++++++ omniread/xlsx/__init__.pyi | 12 ++++++++++++ omniread/xlsx/client.pyi | 10 ++++++++++ omniread/xlsx/parser.pyi | 18 ++++++++++++++++++ omniread/xlsx/parser_base.pyi | 13 +++++++++++++ omniread/xlsx/scraper.pyi | 12 ++++++++++++ pyproject.toml | 2 +- 11 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 omniread/csv/__init__.pyi create mode 100644 omniread/csv/client.pyi create mode 100644 omniread/csv/parser.pyi create mode 100644 omniread/csv/parser_base.pyi create mode 100644 omniread/csv/scraper.pyi create mode 100644 omniread/xlsx/__init__.pyi create mode 100644 omniread/xlsx/client.pyi create mode 100644 omniread/xlsx/parser.pyi create mode 100644 omniread/xlsx/parser_base.pyi create mode 100644 omniread/xlsx/scraper.pyi diff --git a/omniread/csv/__init__.pyi b/omniread/csv/__init__.pyi new file mode 100644 index 0000000..500c89e --- /dev/null +++ b/omniread/csv/__init__.pyi @@ -0,0 +1,12 @@ +from .client import BaseCsvClient, FileSystemCsvClient +from .parser import CsvParser +from .parser_base import CsvParserBase +from .scraper import CsvScraper + +__all__ = [ + "BaseCsvClient", + "FileSystemCsvClient", + "CsvScraper", + "CsvParser", + "CsvParserBase", +] diff --git a/omniread/csv/client.pyi b/omniread/csv/client.pyi new file mode 100644 index 0000000..0df163e --- /dev/null +++ b/omniread/csv/client.pyi @@ -0,0 +1,10 @@ +from abc import ABC, abstractmethod +from pathlib import Path +from typing import Any + +class BaseCsvClient(ABC): + @abstractmethod + def fetch(self, source: Any) -> bytes: ... + +class FileSystemCsvClient(BaseCsvClient): + def fetch(self, path: Path) -> bytes: ... diff --git a/omniread/csv/parser.pyi b/omniread/csv/parser.pyi new file mode 100644 index 0000000..7d75b7b --- /dev/null +++ b/omniread/csv/parser.pyi @@ -0,0 +1,8 @@ +from omniread.core.content import Content + +from .parser_base import CsvParserBase + +class CsvParser(CsvParserBase[list[list[str]]]): + def __init__(self, content: Content) -> None: ... + def parse(self) -> list[list[str]]: ... + def rows(self, *, skip_empty: bool = True) -> list[list[str]]: ... diff --git a/omniread/csv/parser_base.pyi b/omniread/csv/parser_base.pyi new file mode 100644 index 0000000..fdbcaa5 --- /dev/null +++ b/omniread/csv/parser_base.pyi @@ -0,0 +1,13 @@ +from abc import abstractmethod +from typing import Generic, TypeVar + +from omniread.core.content import ContentType +from omniread.core.parser import BaseParser + +T = TypeVar("T") + +class CsvParserBase(BaseParser[T], Generic[T]): + supported_types: set[ContentType] + + @abstractmethod + def parse(self) -> T: ... diff --git a/omniread/csv/scraper.pyi b/omniread/csv/scraper.pyi new file mode 100644 index 0000000..3328806 --- /dev/null +++ b/omniread/csv/scraper.pyi @@ -0,0 +1,12 @@ +from collections.abc import Mapping +from typing import Any + +from omniread.core.content import Content + +from .client import BaseCsvClient + +class CsvScraper: + def __init__(self, *, client: BaseCsvClient) -> None: ... + def fetch( + self, source: Any, *, metadata: Mapping[str, Any] | None = ... + ) -> Content: ... diff --git a/omniread/xlsx/__init__.pyi b/omniread/xlsx/__init__.pyi new file mode 100644 index 0000000..e9b5c3b --- /dev/null +++ b/omniread/xlsx/__init__.pyi @@ -0,0 +1,12 @@ +from .client import BaseXlsxClient, FileSystemXlsxClient +from .parser import XlsxParser +from .parser_base import XlsxParserBase +from .scraper import XlsxScraper + +__all__ = [ + "BaseXlsxClient", + "FileSystemXlsxClient", + "XlsxScraper", + "XlsxParser", + "XlsxParserBase", +] diff --git a/omniread/xlsx/client.pyi b/omniread/xlsx/client.pyi new file mode 100644 index 0000000..48eab7c --- /dev/null +++ b/omniread/xlsx/client.pyi @@ -0,0 +1,10 @@ +from abc import ABC, abstractmethod +from pathlib import Path +from typing import Any + +class BaseXlsxClient(ABC): + @abstractmethod + def fetch(self, source: Any) -> bytes: ... + +class FileSystemXlsxClient(BaseXlsxClient): + def fetch(self, path: Path) -> bytes: ... diff --git a/omniread/xlsx/parser.pyi b/omniread/xlsx/parser.pyi new file mode 100644 index 0000000..33f37aa --- /dev/null +++ b/omniread/xlsx/parser.pyi @@ -0,0 +1,18 @@ +import openpyxl + +from omniread.core.content import Content + +from .parser_base import XlsxParserBase + +class XlsxParser(XlsxParserBase[list[list[str]]]): + def __init__( + self, content: Content, *, data_only: bool = True, read_only: bool = True + ) -> None: ... + @property + def workbook(self) -> openpyxl.Workbook: ... + @property + def sheet_names(self) -> list[str]: ... + def parse(self) -> list[list[str]]: ... + def rows( + self, sheet: int | str | None = None, *, skip_empty: bool = True + ) -> list[list[str]]: ... diff --git a/omniread/xlsx/parser_base.pyi b/omniread/xlsx/parser_base.pyi new file mode 100644 index 0000000..561df4e --- /dev/null +++ b/omniread/xlsx/parser_base.pyi @@ -0,0 +1,13 @@ +from abc import abstractmethod +from typing import Generic, TypeVar + +from omniread.core.content import ContentType +from omniread.core.parser import BaseParser + +T = TypeVar("T") + +class XlsxParserBase(BaseParser[T], Generic[T]): + supported_types: set[ContentType] + + @abstractmethod + def parse(self) -> T: ... diff --git a/omniread/xlsx/scraper.pyi b/omniread/xlsx/scraper.pyi new file mode 100644 index 0000000..df74b98 --- /dev/null +++ b/omniread/xlsx/scraper.pyi @@ -0,0 +1,12 @@ +from collections.abc import Mapping +from typing import Any + +from omniread.core.content import Content + +from .client import BaseXlsxClient + +class XlsxScraper: + def __init__(self, *, client: BaseXlsxClient) -> None: ... + def fetch( + self, source: Any, *, metadata: Mapping[str, Any] | None = ... + ) -> Content: ... diff --git a/pyproject.toml b/pyproject.toml index df6d018..0086a83 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -90,7 +90,7 @@ Versions = "https://git.aetoskia.com/aetos/omniread/tags" packages = { find = { include = ["omniread*"] } } [tool.setuptools.package-data] -omniread = ["py.typed"] +omniread = ['py.typed', '\.pyi?$'] [tool.pytest.ini_options]