Reading Files as Blobs#
Daft can read files as raw bytes into DataFrames using daft.read_blob(), similar to DuckDB's read_blob function. This is useful for loading non-tabular files such as images, audio, PDFs, or any other binary data into a DataFrame, with one row per file.
Basic Usage#
Read files matching a path or glob pattern, where each file becomes a row:
1 2 3 4 | |
1 2 3 4 5 6 | |
1 2 3 4 5 6 | |
Output Schema#
The read_blob function returns a DataFrame with the following columns:
| Column | Type | Description |
|---|---|---|
path | string | Path to the file |
size | int64 | Size of the file in bytes |
content | binary | Raw bytes contents of the file |
Glob Patterns#
read_blob supports the same wildcards as other Daft readers:
1 2 3 4 5 6 7 8 | |
Error Handling#
By default, a download error for any file raises immediately. Set on_error="null" to log the error and fall back to a null content value instead:
1 | |
Common Use Cases#
Decoding Images#
Read image files and decode them for downstream processing:
1 2 3 4 5 | |
Detecting File Types#
Inspect magic bytes to determine the MIME type of each file:
1 2 3 4 5 | |
Relationship to Other APIs#
read_blob is a convenience API composed of daft.from_glob_path() (which lists files with their path and size) and the download expression (which fetches file contents as bytes). Use those building blocks directly if you need more control, such as downloading only a filtered subset of files.