Skip to main content
The FileFetcher retrieves files from your local filesystem. It supports two modes: fetching a single file or fetching multiple files from a directory with optional extension filtering.

Installation

FileFetcher is included with the base Chonkie installation:

Usage

Single File Mode

Fetch a single file by providing the path parameter:

Directory Mode

Fetch multiple files from a directory using the dir parameter:

Extension Filtering

Filter files by extension when using directory mode:

Parameters

path
str
Path to a single file. Cannot be used with dir.
dir
str
Directory to fetch files from. Cannot be used with path.
ext
list[str]
List of file extensions to filter (e.g., [".txt", ".md"]). Only used with dir parameter.

Return Values

  • Single file mode (path provided): Returns a single Path object
  • Directory mode (dir provided): Returns list[Path] containing all matching files

Standalone Usage

You can also use FileFetcher directly without the pipeline:

Error Handling

FileFetcher validates inputs and provides clear error messages:

Best Practices

When working with directories containing many files, always specify ext to avoid processing unwanted files:
While relative paths work, absolute paths make your pipeline more portable:

What’s Next?

After fetching files, you’ll typically want to:
  1. Process them with a Chef to parse content
  2. Chunk them with a Chunker to split into manageable pieces
  3. Refine chunks with Refineries for better quality
See the Pipeline Guide for complete examples.