DuckDB5 min readintermediate
DuckDB and Hugging Face: Querying Datasets Directly
Summary
DuckDB adds an `hf://` protocol that lets you run SQL queries directly against datasets hosted on the Hugging Face Hub, eliminating the need to download files first. The post shows how to read single files, glob multiple files, pin revisions, and handle private datasets.
- Use `SELECT * FROM 'hf://datasets/<user>/<repo>/file.parquet'` to query remote Hugging Face files without downloading.
- Glob patterns (`*.parquet`) let you treat a whole dataset directory as one table and filter rows server‑side.
- Pin to a specific commit or the `~parquet` branch with `@` to ensure reproducible, columnar scans.
- Store a Hugging Face token via DuckDB Secrets Manager to access private or gated datasets.
ML engineers and data scientists who work with Hugging Face datasets can explore and subset data instantly, saving storage and pipeline overhead.
6/10

