windlass.providers.loaders.text¶
text
¶
Plain-text, Markdown, JSON and CSV loaders — all dependency-free.
These four cover a surprising share of real corpora and they need nothing beyond
the standard library, so pip install windlass alone can ingest a folder of
notes, an exported dataset or a JSONL dump.
Example
import tempfile, pathlib d = pathlib.Path(tempfile.mkdtemp()) _ = (d / "note.md").write_text("# Title\n\nBody text.") docs = MarkdownLoader().load(d) docs[0].metadata["title"] 'Title'
TextLoader
¶
TextLoader(
*,
encoding: str = "utf-8",
metadata: dict[str, Any] | None = None,
recursive: bool = True,
on_error: str = "skip",
name: str | None = None,
**config: Any
)
Bases: Loader
Loads plain-text files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoding
|
str
|
Text encoding. Falls back to a lenient decode when the file turns out not to be valid in this encoding, so one mislabelled file does not abort a corpus. |
'utf-8'
|
**config
|
Any
|
Forwarded to :class: |
{}
|
Example
import tempfile, pathlib p = pathlib.Path(tempfile.mkdtemp()) / "a.txt" _ = p.write_text("hello") TextLoader().load(p)[0].content 'hello'
Source code in src\windlass\interfaces\loader.py
aload_source
async
¶
Read one text file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
SourceLike
|
A path or a bytes payload. |
required |
Returns:
| Type | Description |
|---|---|
list[Document]
|
A single-element list holding the file's text. |
Raises:
| Type | Description |
|---|---|
IngestionError
|
When the file cannot be read. |
Source code in src\windlass\providers\loaders\text.py
MarkdownLoader
¶
Bases: Loader
Loads Markdown files and extracts their structure.
Pulls out the YAML front-matter (parsed as key/value pairs without needing
PyYAML), the first # heading as a title, and the full heading list — all
of which become metadata you can filter and cite on.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
strip_frontmatter
|
bool
|
Remove the front-matter block from the content. |
True
|
**config
|
Any
|
Forwarded to :class: |
{}
|
Example
import tempfile, pathlib p = pathlib.Path(tempfile.mkdtemp()) / "d.md" _ = p.write_text("---\ntag: guide\n---\n# Setup\n\nRun it.") doc = MarkdownLoader().load(p)[0] doc.metadata["tag"], doc.metadata["title"] ('guide', 'Setup')
Source code in src\windlass\providers\loaders\text.py
aload_source
async
¶
Read one Markdown file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
SourceLike
|
A path or a bytes payload. |
required |
Returns:
| Type | Description |
|---|---|
list[Document]
|
A single-element list. |
Source code in src\windlass\providers\loaders\text.py
JSONLoader
¶
JSONLoader(
*,
content_key: str | None = None,
metadata_keys: list[str] | None = None,
jq_path: str | None = None,
**config: Any
)
Bases: Loader
Loads JSON and JSON Lines files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content_key
|
str | None
|
Field to use as document content. When omitted the whole record is pretty-printed, which is right for heterogeneous data. |
None
|
metadata_keys
|
list[str] | None
|
Fields copied into metadata. |
None
|
jq_path
|
str | None
|
Dotted path into the document to find the array of records,
e.g. |
None
|
**config
|
Any
|
Forwarded to :class: |
{}
|
Example
import tempfile, pathlib, json p = pathlib.Path(tempfile.mkdtemp()) / "d.json" _ = p.write_text(json.dumps([{"text": "a", "id": 1}, {"text": "b", "id": 2}])) docs = JSONLoader(content_key="text").load(p) [d.content for d in docs]['a', 'b']
Source code in src\windlass\providers\loaders\text.py
aload_source
async
¶
Read a JSON or JSONL file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
SourceLike
|
A path or a bytes payload. |
required |
Returns:
| Type | Description |
|---|---|
list[Document]
|
One document per record. |
Raises:
| Type | Description |
|---|---|
IngestionError
|
When the file is not valid JSON. |
Source code in src\windlass\providers\loaders\text.py
CSVLoader
¶
CSVLoader(
*,
mode: str = "row",
content_columns: list[str] | None = None,
metadata_columns: list[str] | None = None,
delimiter: str | None = None,
max_rows: int | None = None,
**config: Any
)
Bases: Loader
Loads delimited data files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
str
|
|
'row'
|
content_columns
|
list[str] | None
|
Columns included in the content. |
None
|
metadata_columns
|
list[str] | None
|
Columns copied into metadata. |
None
|
delimiter
|
str | None
|
Field separator. Inferred from the extension when omitted. |
None
|
max_rows
|
int | None
|
Stop after this many rows. |
None
|
**config
|
Any
|
Forwarded to :class: |
{}
|
Example
import tempfile, pathlib p = pathlib.Path(tempfile.mkdtemp()) / "d.csv" _ = p.write_text("name,role\nada,engineer\ngrace,admiral\n") docs = CSVLoader().load(p) len(docs), "ada" in docs[0].content (2, True)
Source code in src\windlass\providers\loaders\text.py
aload_source
async
¶
Read a delimited file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
SourceLike
|
A path or a bytes payload. |
required |
Returns:
| Type | Description |
|---|---|
list[Document]
|
One document per row, or one for the whole table. |
Raises:
| Type | Description |
|---|---|
IngestionError
|
When the file cannot be parsed. |