windlass.providers.loaders.office¶
office
¶
PDF, Word, PowerPoint and Excel loaders.
Install with::
pip install "windlass[loaders]"
Every loader here runs its blocking parser on a worker thread, so ingesting a folder of 500 PDFs uses the whole machine instead of one core.
Example
from windlass import Windlass # doctest: +SKIP docs = Windlass.loader("pdf").load("./reports") # doctest: +SKIP
PDFLoader
¶
PDFLoader(
*,
per_page: bool = True,
extract_metadata: bool = True,
password: str | None = None,
min_page_chars: int = 10,
**config: Any
)
Bases: Loader
Extracts text from PDF files using pypdf.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
per_page
|
bool
|
Emit one document per page (recommended — page numbers become citations) rather than one per file. |
True
|
extract_metadata
|
bool
|
Copy the PDF's own metadata (title, author, ...) onto every document. |
True
|
password
|
str | None
|
Password for encrypted PDFs. |
None
|
min_page_chars
|
int
|
Skip pages with less text than this. Filters out scan artefacts and blank separator pages. |
10
|
**config
|
Any
|
Forwarded to :class: |
{}
|
Raises:
| Type | Description |
|---|---|
MissingDependencyError
|
When |
IngestionError
|
When the PDF is corrupt or encrypted without a password. |
Note
pypdf extracts embedded text. A scanned PDF contains images, not
text, and will come back empty — run it through the ocr preprocessor
or the image loader instead.
Source code in src\windlass\providers\loaders\office.py
aload_source
async
¶
Extract text from one PDF.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
SourceLike
|
A path or a bytes payload. |
required |
Returns:
| Type | Description |
|---|---|
list[Document]
|
One document per page, or one for the whole file. |
Raises:
| Type | Description |
|---|---|
IngestionError
|
When the file cannot be parsed. |
Source code in src\windlass\providers\loaders\office.py
DocxLoader
¶
Bases: Loader
Extracts text from .docx files using python-docx.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
include_tables
|
bool
|
Render tables as pipe-delimited text and append them. |
True
|
include_headers
|
bool
|
Include header and footer text. |
False
|
**config
|
Any
|
Forwarded to :class: |
{}
|
Raises:
| Type | Description |
|---|---|
MissingDependencyError
|
When |
Note
Only the modern .docx format is supported. Legacy .doc files must
be converted first (libreoffice --convert-to docx).
Source code in src\windlass\providers\loaders\office.py
aload_source
async
¶
Extract text from one Word document.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
SourceLike
|
A path or a bytes payload. |
required |
Returns:
| Type | Description |
|---|---|
list[Document]
|
A single-element list. |
Raises:
| Type | Description |
|---|---|
IngestionError
|
When the file cannot be parsed. |
Source code in src\windlass\providers\loaders\office.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | |
PptxLoader
¶
Bases: Loader
Extracts text from .pptx decks using python-pptx.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
per_slide
|
bool
|
One document per slide (recommended — slide numbers are natural citations). |
True
|
include_notes
|
bool
|
Include the speaker notes, which often carry the actual argument the slide only gestures at. |
True
|
**config
|
Any
|
Forwarded to :class: |
{}
|
Raises:
| Type | Description |
|---|---|
MissingDependencyError
|
When |
Source code in src\windlass\providers\loaders\office.py
aload_source
async
¶
Extract text from one deck.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
SourceLike
|
A path or a bytes payload. |
required |
Returns:
| Type | Description |
|---|---|
list[Document]
|
One document per slide, or one for the whole deck. |
Raises:
| Type | Description |
|---|---|
IngestionError
|
When the file cannot be parsed. |
Source code in src\windlass\providers\loaders\office.py
XlsxLoader
¶
XlsxLoader(
*,
per_sheet: bool = True,
max_rows: int = 10000,
header_row: int = 1,
skip_empty: bool = True,
**config: Any
)
Bases: Loader
Extracts data from .xlsx workbooks using openpyxl.
Sheets are rendered as Markdown tables, which models read considerably better than raw CSV — the header row stays visually attached to its columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
per_sheet
|
bool
|
One document per sheet. |
True
|
max_rows
|
int
|
Row ceiling per sheet. Guards against a stray million-row sheet. |
10000
|
header_row
|
int
|
Which row holds the column names, 1-based. |
1
|
skip_empty
|
bool
|
Skip rows where every cell is empty. |
True
|
**config
|
Any
|
Forwarded to :class: |
{}
|
Raises:
| Type | Description |
|---|---|
MissingDependencyError
|
When |
Source code in src\windlass\providers\loaders\office.py
aload_source
async
¶
Extract data from one workbook.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
SourceLike
|
A path or a bytes payload. |
required |
Returns:
| Type | Description |
|---|---|
list[Document]
|
One document per sheet, or one for the whole workbook. |
Raises:
| Type | Description |
|---|---|
IngestionError
|
When the file cannot be parsed. |