OfficeReader#

class scikitplot.corpus.OfficeReader(input_path, chunker=None, filter_=None, filename_override=None, default_language=None, source_uri=None, source_provenance=<factory>, custom_extractor=None, custom_extractor_kwargs=<factory>, max_text_chars=268435456, max_text_chars_per_byte=50, on_text_limit='refuse', notes=True, hidden=True, rows_per_chunk=500, headings=True, code_files='refuse', max_file_bytes=524288000, max_part_bytes=268435456, max_part_bytes_per_byte=50, max_parts=100000)[source]#

Read office documents: Office Open XML and OpenDocument.

Word documents (.docx, .docm, .dotx, .dotm) give their body in document order, a chunk per run of paragraphs between tables and a chunk per table, then footnotes and endnotes. Presentations (.pptx, .pptm, .potx, .potm, .ppsx, .ppsm) give a chunk per slide in the order of the deck, then, if asked, its notes. Workbooks (.xlsx, .xlsm, .xltx, .xltm) give each worksheet in workbook order, rows_per_chunk rows a chunk.

OpenDocument files read the same way: text documents (.odt, .ott) as paragraphs, tables and notes; spreadsheets (.ods, .ots) as sheets of rows; presentations and drawings (.odp, .otp, .odg, .otg) as a chunk per page, then its notes; a formula (.odf) as its annotation text; and the flat single-XML forms (.fodt, .fods, .fodp, .fodg).

Parameters:
input_pathpathlib.Path

Path to the file.

notesbool, optional

Read speaker notes (PowerPoint) and footnotes and endnotes (Word). Default: True.

hiddenbool, optional

Read slides and sheets marked hidden, and Word text formatted as hidden (w:vanish). Their chunks carry hidden=True (slides, sheets) or has_hidden_text=True (Word). False leaves all of them out. Default: True.

rows_per_chunkint, optional

Most spreadsheet rows in one chunk; a longer sheet gives several chunks. Default: 500.

headingsbool, optional

Start a new chunk at each heading of a text document and record the heading on the chunks under it. False reads headings as paragraphs. Default: True.

code_files{“refuse”, “skip”}, optional

What happens to an add-in, macro sheet or workspace: "refuse" raises ValueError saying what the file is; "skip" logs that warning and yields nothing, so a large folder is read past such files. Neither ever reads one. Default: "refuse".

max_file_bytesint, optional

Largest file read. Default: 500 MB.

max_part_bytesint, optional

Largest XML part read, uncompressed: the bound on memory, and on a part that a small ZIP inflates into a huge one. Default: 256 MB.

max_part_bytes_per_bytefloat or None, optional

Most uncompressed bytes of one XML part per byte of the file: a part may be max(max_part_bytes_per_byte x file size, 1 Mi) bytes, and never more than max_part_bytes. A part is parsed whole, at several times its size in memory, and a ZIP can inflate one about a thousand times, so this keeps the cost of a file in proportion to its size. Not applied to a flat OpenDocument file (one XML file, not compressed). Default: 50; None: no ratio limit.

max_partsint, optional

Most parts a package may hold. Default: 100 000.

max_text_charsint or None, optional

Most characters of text one file may yield, over all its chunks: the bound on what a small file can expand into (a spreadsheet cell repeated across columns and rows stays within each sheet limit, yet a 500-byte file could yield 34 billion characters). None: no limit. Default: 256 Mi characters.

on_text_limit{“refuse”, “truncate”}, optional

What happens past max_text_chars, as for every reader (see on_text_limit). Default: "refuse".

chunker, filter_, filename_override, default_languageoptional

Inherited from DocumentReader.

Attributes:
file_typeslist of str

The Office Open XML and OpenDocument extensions above.

Raises:
ValueError

If a limit is not a positive int; at read time, if the file is too large, is not a package or a flat OpenDocument file (a legacy .doc/.ppt or an encrypted file is named as such), has no main part the reader knows, holds a part twice, over a limit or not well-formed XML, or has a spreadsheet cell past a sheet’s size (OpenDocument: repeated past it; Excel: referenced past column XFD).

Parameters:
  • input_path (Path)

  • chunker (ChunkerBase | None)

  • filter_ (FilterBase | None)

  • filename_override (str | None)

  • default_language (str | None)

  • source_uri (str | None)

  • source_provenance (dict[str, Any])

  • custom_extractor (Any | None)

  • custom_extractor_kwargs (dict[str, Any])

  • max_text_chars (int | None)

  • max_text_chars_per_byte (float | None)

  • on_text_limit (str)

  • notes (bool)

  • hidden (bool)

  • rows_per_chunk (int)

  • headings (bool)

  • code_files (str)

  • max_file_bytes (int)

  • max_part_bytes (int)

  • max_part_bytes_per_byte (float | None)

  • max_parts (int)

See also

scikitplot.corpus._readers.PDFReader

PDF documents.

scikitplot.corpus._readers.ZipReader

Archives of other files.

Notes

Chunks. Every chunk has text, raw_text, section_type, part (the package part it came from) and has_macros (the package holds a VBA project; it is never run). Slides add page_number (0-based position in the deck) and hidden; notes add page_number of their slide. Word tables are section_type "table", cells separated by tabs and rows by lines; footnotes and endnotes are "footnote". Sheet chunks are "table", rows by line and cells by tab at their column, with page_number (0-based sheet position), sheet (its name), row_start, row_end (1-based row numbers) and hidden. A cell gives its stored value: the cached result of a formula (formulas are never computed), dates as their serial number, booleans as TRUE/FALSE.

Hidden text. Word text formatted as hidden is not shown to a reader but is in the file; text placed there to steer a model that reads the document is one reason to know. A chunk that holds any carries has_hidden_text=True (the key is absent otherwise), and hidden=False leaves the hidden runs out. OpenDocument text counts the same way: a conditional hidden text (text:hidden-text), a paragraph marked hidden (text:hidden-paragraph) and a section not displayed (text:display="none", or "condition" while hidden). A table in a hidden section is left out with hidden=False but not flagged otherwise. In Word a style hides text too: a character style, the paragraph’s style or the document default with w:vanish, each through the styles it is based on. In OpenDocument a span or paragraph style with text:display="none" hides too, through its parent styles, from content.xml and styles.xml.

Headings. In Word and OpenDocument text, a heading starts a new chunk (its text is the chunk’s first line), and that chunk and the tables under it carry heading and heading_level (1 is the top) until the next heading, so a chunk keeps the section it belongs to. heading_path lists the headings it sits under, from the top down (["Methods", "Sampling"]). A slide’s chunks, and its notes, carry its title (the title or ctrTitle placeholder) the same way, at level 1. Word headings are found by outline level, by the built-in heading 1 to heading 9 styles, and by styles based on them.

What decides. The content, not the extension: a .docx that is a presentation reads as one, and the Strict and Transitional conformance classes of Office Open XML read alike. The legacy names (.doc, .dot, .wbk, .xls, .xlt, .ppt, .pot, .pps) are registered too: a legacy binary file under them is refused with the reason, and a modern package saved under such a name is read. Add-ins, macro sheets and workspaces (.wll, .wwl, .xll, .xla, .xlam, .xlm, .xlw, .ppa, .ppam and the Mac variants) are code or settings, not documents, and are refused by name.

Order. Slides follow the deck’s list (p:sldIdLst), not their part names, so slide11.xml can come before slide2.xml.

Security. The package is read in memory; part names never become paths. Every XML part is parsed with entity declarations and external entities refused (_xml_safety). Relationships to external targets, or to targets above the package root, are not followed. Tracked deletions are dropped; fields read as their cached text.

Memory. Each part is parsed whole, not streamed, at about eight times its uncompressed size, so memory is bounded by the part limit in force: the smaller of max_part_bytes and max(max_part_bytes_per_byte x file size, 1 Mi).

OpenDocument specifics. Cells give their displayed text, so dates read as shown. Repeated cells and rows are expanded; a repeat of cells or rows with a value beyond 16 384 columns or 1 048 576 rows is refused. Hidden pages and sheets are not told apart (the flag lives in a style), so their chunks carry no hidden key. A package whose manifest lists encrypted parts is refused.

Not read (yet): headers and footers, comments, charts, SmartArt, embedded images (no OCR), slide masters and layouts; number formats in Excel (dates read as numbers); chartsheets; legacy binary files (.doc, .xls, .ppt).

Examples

>>> from pathlib import Path
>>> from scikitplot.corpus._base import DocumentReader
>>> reader = DocumentReader.create(Path("deck.pptx"), notes=False)
>>> docs = list(reader.get_documents())
property backend_reports: tuple[dict[str, Any], ...]#

Return structured optional-backend reports from the current run.

Reports are JSON-compatible dictionaries. They intentionally retain exception type/message strings rather than live exception objects, so fail-soft readers remain observable without retaining traceback object graphs. get_documents clears old reports at the start of each run.

Returns:
tuple of dict

One report per backend operation that opted into central orchestration. Empty when no optional backend operation ran.

chunker: ChunkerBase | None = None#

Chunker to apply to each raw text block. None means each raw chunk is used as-is (one CorpusDocument per raw chunk).

clear_backend_reports()[source]#

Clear structured optional-backend reports on this reader instance.

Return type:

None

code_files: str = 'refuse'#

"refuse".

Type:

"refuse" or "skip" an add-in, macro sheet or workspace. Default

classmethod create(*input_path, chunker=None, filter_=None, filename_override=None, default_language=None, source_type=None, source_title=None, source_author=None, source_date=None, collection_id=None, doi=None, isbn=None, **kwargs)[source]#

Instantiate the appropriate reader for one or more sources.

Accepts any mix of file paths, URL strings, and pathlib.Path objects — in any order. URL strings (those starting with http:// or https://) are automatically detected and routed to from_url; everything else is treated as a local file path and dispatched by extension via the registry.

Parameters:
*input_pathstr or pathlib.Path

One or more source paths or URL strings. Each element is classified independently:

  • str matching ^https?:// (case-insensitive) — treated as a URL and routed to from_url. Must be passed as a plain ``str``, not wrapped in pathlib.Path; wrapping collapses the double-slash (https:// → https:/) and breaks URL detection.

  • str not matching the URL pattern — treated as a local file path and converted to pathlib.Path internally.

  • pathlib.Path — always treated as a local file path and dispatched by extension via the reader registry.

Pass a single value for the common case; pass multiple values to get a _MultiSourceReader that chains all their documents in order.

chunkerChunkerBase or None, optional

Chunker injected into every reader. Default: None.

filter_FilterBase or None, optional

Filter injected into every reader. Default: None (DefaultFilter).

filename_overridestr or None, optional

Override the input_path label. Only applied when input_path contains exactly one source. Default: None.

default_languagestr or None, optional

ISO 639-1 language code applied to all sources. Default: None.

source_typeSourceType, list[SourceType or None], or None, optional

Semantic label for the source kind. When input_path has more than one element you may pass a list of the same length to assign a distinct type per source; None entries in the list mean “infer from extension / URL”. A single value is broadcast to all sources. Default: None.

source_titlestr or None, optional

Title propagated into every yielded document. Default: None.

source_authorstr or None, optional

Author propagated into every yielded document. Default: None.

source_datestr or None, optional

ISO 8601 publication date. Default: None.

collection_idstr or None, optional

Corpus collection identifier. Default: None.

doistr or None, optional

Digital Object Identifier (file sources only). Default: None.

isbnstr or None, optional

ISBN (file sources only). Default: None.

**kwargsAny

Extra keyword arguments forwarded verbatim to each concrete reader constructor (e.g. transcribe=True for AudioReader, backend="easyocr" for ImageReader).

Returns:
DocumentReader

A single reader when input_path has exactly one element (backward compatible with every existing call site). A _MultiSourceReader when input_path has more than one element — it implements the same get_documents() interface and chains documents from all sub-readers in order.

Raises:
ValueError

If input_path is empty, or if a source URL is invalid, or if no reader is registered for a file’s extension.

TypeError

If any element of input_path is not a str or pathlib.Path.

Parameters:
Return type:

Self

Notes

URL auto-detection: A str element is treated as a URL when it matches ^https?:// (case-insensitive). All other strings and all pathlib.Path objects are treated as local file paths. This means you no longer need to call from_url explicitly — just pass the URL string to create.

Per-source source_type: When passing multiple input_path with different media types, supply a list:

DocumentReader.create(
    Path("podcast.mp3"),
    "report.pdf",
    "https://iris.who.int/.../content",  # returns image/jpeg
    source_type=[SourceType.PODCAST, SourceType.RESEARCH, SourceType.IMAGE],
)

Reader-specific kwargs (forwarded via **kwargs):

Examples

Single file (backward-compatible):

>>> reader = DocumentReader.create(Path("hamlet.txt"))
>>> docs = list(reader.get_documents())

URL string auto-detected — no from_url() call required:

>>> reader = DocumentReader.create(
...     "https://en.wikipedia.org/wiki/Python_(programming_language)"
... )

Mixed multi-source batch:

>>> reader = DocumentReader.create(
...     Path("podcast.mp3"),
...     "report.pdf",
...     "https://iris.who.int/api/bitstreams/abc/content",
...     source_type=[SourceType.PODCAST, SourceType.RESEARCH, SourceType.IMAGE],
... )
>>> docs = list(reader.get_documents())  # chained stream from all three
custom_extractor: Any | None = None#

User-supplied extraction callable that replaces get_raw_chunks entirely for this reader instance.

When set, _iter_raw_chunks calls custom_extractor(self.input_path, **custom_extractor_kwargs) and normalises the return value through normalize_extractor_output. The built-in get_raw_chunks implementation is not called.

This hook is available on every reader class (ALTOReader, TextReader, PDFReader, ImageReader, etc.) without any subclassing — simply pass a callable at construction time.

Callable contract

def my_extractor(path: pathlib.Path, **kwargs) -> ExtractorOutput

where ExtractorOutput is str, list[str], dict, or list[dict] — the same contract as CustomReader.

Examples

Override PDF extraction with pdfplumber for a single reader:

import pdfplumber
from pathlib import Path
from scikitplot.corpus._base import DocumentReader

def plumber_fn(path, **kw):
    with pdfplumber.open(path) as pdf:
        return [{"text": p.extract_text() or "", "page_number": i}
                for i, p in enumerate(pdf.pages)]

reader = DocumentReader.create(
    Path("report.pdf"),
    custom_extractor=plumber_fn,
)
docs = list(reader.get_documents())
custom_extractor_kwargs: dict[str, Any][source]#

Extra keyword arguments forwarded to custom_extractor on every invocation. Merged into the call as **custom_extractor_kwargs.

Examples

reader = DocumentReader.create(
    Path("report.pdf"),
    custom_extractor=my_fn,
    custom_extractor_kwargs={"password": "s3cret", "pages": [0, 1, 2]},
)
default_language: str | None = None#

ISO 639-1 language code to assign when the source has no language info.

property file_name: str#

Effective filename used in document labels.

Returns filename_override when set; otherwise returns input_path.name.

Returns:
str

File name string (not a full path).

Examples

>>> from pathlib import Path
>>> reader = TextReader(input_path=Path("/data/corpus.txt"))
>>> reader.file_name
'corpus.txt'
file_type: ClassVar[str | None][source]#

Single file extension this reader handles (lowercase, including leading dot). E.g. ".txt", ".xml", ".zip".

For readers that handle multiple extensions, define file_types (plural) instead. Exactly one of file_type or file_types must be defined on every concrete subclass.

file_types: ClassVar[list[str] | None] = ['.docx', '.docm', '.dotx', '.dotm', '.pptx', '.pptm', '.potx', '.potm', '.ppsx', '.ppsm', '.xlsx', '.xlsm', '.xltx', '.xltm', '.odt', '.ott', '.ods', '.ots', '.odp', '.otp', '.odg', '.otg', '.odf', '.fodt', '.fods', '.fodp', '.fodg', '.doc', '.dot', '.wbk', '.xls', '.xlt', '.ppt', '.pot', '.pps', '.ppa', '.ppam', '.wll', '.wwl', '.xla', '.xla5', '.xla8', '.xla_', '.xlam', '.xll', '.xll_', '.xlm', '.xlw']#

List of file extensions this reader handles (lowercase, leading dot). Use instead of file_type when a single reader class should be registered for several extensions — e.g. an image reader for [".png", ".jpg", ".jpeg", ".gif", ".webp"].

When both file_type and file_types are defined on the same class, file_types takes precedence and file_type is ignored.

filename_override: str | None = None#

Override for the input_path label in generated documents.

filter_: FilterBase | None = None#

Filter applied after chunking. None triggers the DefaultFilter.

classmethod from_manifest(manifest_path, *, chunker=None, filter_=None, default_language=None, source_type=None, source_title=None, source_author=None, source_date=None, collection_id=None, doi=None, isbn=None, encoding='utf-8', **kwargs)[source]#

Build a _MultiSourceReader from a manifest file.

The manifest is a text file with one source per line — either a file path or a URL. Blank lines and lines starting with # are ignored. JSON manifests (a list of strings or objects) are also supported.

Parameters:
manifest_pathstr or pathlib.Path

Path to the manifest file. Supported formats:

  • .txt / .manifest — one source per line.

  • .json — a JSON array of strings (sources) or objects with at least a "source" key (and optional "source_type", "source_title" per-entry overrides).

chunkerChunkerBase or None, optional

Chunker applied to all sources. Default: None.

filter_FilterBase or None, optional

Filter applied to all sources. Default: None.

default_languagestr or None, optional

ISO 639-1 language code. Default: None.

source_typeSourceType or None, optional

Override source type for all sources. Default: None.

source_titlestr or None, optional

Override title for all sources. Default: None.

source_authorstr or None, optional

Override author for all sources. Default: None.

source_datestr or None, optional

Override date for all sources. Default: None.

collection_idstr or None, optional

Collection identifier. Default: None.

doistr or None, optional

DOI override. Default: None.

isbnstr or None, optional

ISBN override. Default: None.

encodingstr, optional

Text encoding for .txt manifests. Default: "utf-8".

**kwargsAny

Forwarded to each reader constructor.

Returns:
_MultiSourceReader

Multi-source reader chaining all manifest entries.

Raises:
ValueError

If manifest_path does not exist or is empty after filtering blank and comment lines.

ValueError

If the manifest format is not recognised.

Parameters:
Return type:

_MultiSourceReader

Notes

Per-entry overrides in JSON manifests: each entry may be an object with:

{
    "source": "https://example.com/report.pdf",
    "source_type": "research",
    "source_title": "Annual Report 2024",
}

String-level source_type values are coerced via SourceType(value) and an invalid value raises ValueError.

Examples

Text manifest sources.txt:

# WHO corpus
https://www.who.int/europe/news/item/...
https://youtu.be/rwPISgZcYIk
WHO-EURO-2025.pdf
scan.jpg

Usage:

reader = DocumentReader.from_manifest(
    Path("sources.txt"),
    collection_id="who-corpus",
)
docs = list(reader.get_documents())
classmethod from_url(url, *, chunker=None, filter_=None, filename_override=None, default_language=None, source_type=None, source_title=None, source_author=None, source_date=None, collection_id=None, doi=None, isbn=None, **kwargs)[source]#

Instantiate the appropriate reader for a URL source.

Dispatches to YouTubeReader for YouTube URLs and to WebReader for all other http:// / https:// URLs.

Parameters:
urlstr

Full URL string. Must start with http:// or https://.

chunkerChunkerBase or None, optional

Chunker to inject. Default: None.

filter_FilterBase or None, optional

Filter to inject. Default: None (DefaultFilter).

filename_overridestr or None, optional

Override for the input_path label. Default: None.

default_languagestr or None, optional

ISO 639-1 language code. Default: None.

source_typeSourceType or None, optional

Semantic label for the source. Default: None.

source_titlestr or None, optional

Title of the source work. Default: None.

source_authorstr or None, optional

Primary author. Default: None.

source_datestr or None, optional

Publication date in ISO 8601 format. Default: None.

collection_idstr or None, optional

Corpus collection identifier. Default: None.

doistr or None, optional

Digital Object Identifier. Default: None.

isbnstr or None, optional

International Standard Book Number. Default: None.

**kwargsAny

Additional kwargs forwarded to the reader constructor (e.g. include_auto_generated=False for YouTubeReader).

Returns:
DocumentReader

YouTubeReader or WebReader instance.

Raises:
ValueError

If url does not start with http:// or https://.

ImportError

If the required reader class is not registered (i.e. scikitplot.corpus._readers has not been imported yet).

Parameters:
  • url (str)

  • chunker (ChunkerBase | None)

  • filter_ (FilterBase | None)

  • filename_override (str | None)

  • default_language (str | None)

  • source_type (SourceType | None)

  • source_title (str | None)

  • source_author (str | None)

  • source_date (str | None)

  • collection_id (str | None)

  • doi (str | None)

  • isbn (str | None)

  • kwargs (Any)

Return type:

Self

Notes

Prefer :meth:`create` for new code. Passing a URL string to create automatically calls from_url — you rarely need to call from_url directly.

Examples

>>> reader = DocumentReader.from_url("https://en.wikipedia.org/wiki/Python")
>>> docs = list(reader.get_documents())
>>> yt = DocumentReader.from_url("https://www.youtube.com/watch?v=rwPISgZcYIk")
>>> docs = list(yt.get_documents())
get_documents()[source]#

Yield validated CorpusDocument instances for the input file.

Orchestrates the full per-file pipeline:

  1. validate_input — fail fast if file is missing.

  2. get_raw_chunks — format-specific text extraction.

  3. Chunker (if set) — sub-segments each raw block.

  4. CorpusDocument construction with validated schema.

  5. Filter — discards noise documents.

Yields:
CorpusDocument

Validated documents that passed the filter.

Raises:
ValueError

If the input file is missing or the format is invalid.

Return type:

Generator[CorpusDocument, None, None]

Notes

The global chunk_index counter is monotonically increasing across all raw chunks and sub-chunks for a single file, ensuring that (input_path, chunk_index) is a unique key within one reader run.

Omitted-document statistics are logged at INFO level after processing each file.

Examples

>>> from pathlib import Path
>>> reader = DocumentReader.create(Path("corpus.txt"))
>>> docs = list(reader.get_documents())
>>> all(isinstance(d, CorpusDocument) for d in docs)
True
get_raw_chunks()[source]#

Yield the text of the document, a chunk at a time.

Yields:
dict

See the Notes of OfficeReader.

Raises:
ValueError

See OfficeReader.

Return type:

Generator[dict[str, Any], None, None]

headings: bool = True#

True.

Type:

Split text documents at headings and record them. Default

hidden: bool = True#

True.

Type:

Read hidden slides, sheets and Word hidden text. Default

input_path: Path[source]#

Path to the source file.

For URL-based readers (WebReader, YouTubeReader), pass pathlib.Path(url_string) here and set source_uri to the original URL string. validate_input() is overridden in those subclasses to skip the file-existence check.

max_file_bytes: int = 524288000#

500 MB.

Type:

Largest file read. Default

max_part_bytes: int = 268435456#

256 MB.

Type:

Largest XML part read, uncompressed. Default

max_part_bytes_per_byte: float | None = 50#

1 Mi bytes).

Default: 50; None: no ratio limit.

Type:

Most uncompressed bytes of a part per byte of the file (floor

max_parts: int = 100000#

100 000.

Type:

Most parts a package may hold. Default

max_text_chars: int | None = 268435456#

256 Mi.

Enforced by DocumentReader with on_text_limit; this reader only sets the default.

Type:

Most characters of text one file yields; None

Type:

no limit. Default

max_text_chars_per_byte: float | None = 50#

1 Mi characters).

Default: 50; None: no ratio limit. See max_text_chars_per_byte.

Type:

Most characters of text per byte of the file (floor

notes: bool = True#

True.

Type:

Read speaker notes, footnotes and endnotes. Default

on_text_limit: str = 'refuse'#

What happens past the text limit (max_text_chars, max_text_chars_per_byte): "refuse" (default) raises ValueError; "truncate" keeps exactly the first max_text_chars characters, marks the chunk it cuts text_truncated=True (none when the limit falls between chunks) and logs a warning either way.

rows_per_chunk: int = 500#

500.

Type:

Most spreadsheet rows in one chunk. Default

source_provenance: dict[str, Any][source]#

Provenance overrides propagated into every yielded CorpusDocument.

Keys may include "source_type", "source_title", "source_author", and "collection_id". Populated by create / from_url from their keyword arguments.

source_uri: str | None = None#

Original URI for URL-based readers (web pages, YouTube videos).

Set this to the full URL string when input_path is a synthetic pathlib.Path wrapping a URL. File-based readers leave this None.

Examples

>>> reader = WebReader(
...     input_path=Path("https://example.com/article"),
...     source_uri="https://example.com/article",
... )
classmethod subclass_by_type()[source]#

Return a copy of the extension → reader class registry.

Returns:
dict

Mapping of file extension (str) → reader class. Returns a shallow copy so callers cannot accidentally mutate the registry.

Return type:

dict[str, type[DocumentReader]]

Examples

>>> registry = DocumentReader.subclass_by_type()
>>> ".txt" in registry
True
classmethod supported_types()[source]#

Return a sorted list of file extensions supported by registered readers.

Returns:
list of str

Lowercase file extensions, each including the leading dot. E.g. ['.pdf', '.txt', '.xml', '.zip'].

Return type:

list[str]

Examples

>>> DocumentReader.supported_types()
['.pdf', '.txt', '.xml', '.zip']
validate_input()[source]#

Assert that the input file exists and is readable.

Raises:
ValueError

If input_path does not exist or is not a regular file.

Return type:

None

Notes

Called automatically by get_documents before iterating. Can also be called eagerly after construction to fail fast.

Examples

>>> reader = DocumentReader.create(Path("missing.txt"))
>>> reader.validate_input()
Traceback (most recent call last):
    ...
ValueError: Input file does not exist: missing.txt