Hugging Face Datasets Python API Docs | dltHub
Build a Hugging Face Datasets-to-database pipeline in Python using dlt with AI Workbench support for Claude Code, Cursor, and Codex.
Last updated:
Hugging Face Datasets REST API is a REST API that exposes dataset metadata, previews, slices, search, filtering, parquet exports and statistics for datasets hosted on the Hugging Face Hub. The REST API base URL is https://datasets-server.huggingface.co and All requests that access gated or private datasets require a Bearer user token; public dataset metadata/endpoints are often accessible anonymously..
dlt is an open-source Python library that handles authentication, pagination, and schema evolution automatically. dlthub provides AI context files that enable code assistants to generate production-ready pipelines. Install with uv pip install "dlt[workspace]" and start loading Hugging Face Datasets data in under 10 minutes.
What data can I load from Hugging Face Datasets?
Here are some of the endpoints you can load from Hugging Face Datasets:
| Resource | Endpoint | Method | Data selector | Description |
|---|---|---|---|---|
| is_valid | /is-valid?dataset={dataset} | GET | Check whether a dataset supports viewer features (preview, viewer, search, filter, statistics). | |
| splits | /splits?dataset={dataset} | GET | splits | Return list of configs and splits for a dataset. |
| first_rows | /first-rows?dataset={dataset}&config={config}&split={split} | GET | rows | Return first 100 rows and features metadata (rows, features). |
| rows | /rows?dataset={dataset}&config={config}&split={split}&offset={offset}&length={length} | GET | rows | Return a slice of rows (max length 100) plus features and pagination fields. |
| search | /search?dataset={dataset}&config={config}&split={split}&query={query}&offset={offset}&length={length} | GET | rows | Search text in string columns; returns same structure as /rows. |
| filter | /filter?dataset={dataset}&config={config}&split={split}&where={where}&orderby={orderby}&offset={offset}&length={length} | GET | rows | Filter rows by expression; returns same structure as /rows. |
| parquet | /parquet?dataset={dataset} | GET | parquet_files | Return list of parquet file URLs per split. |
| size | /size?dataset={dataset} | GET | size | Return dataset size in rows and bytes. |
| statistics | /statistics?dataset={dataset}&config={config}&split={split} | GET | statistics | Return statistics about a split. |
| croissant | /croissant?dataset={dataset} | GET | Return Croissant metadata for dataset. |
How do I authenticate with the Hugging Face Datasets API?
Authentication uses Hugging Face user access tokens. For private/gated datasets include an Authorization header: Authorization: Bearer <API_TOKEN>. Public dataset endpoints can be accessed without authentication.
1. Get your credentials
- Sign in to https://huggingface.co (or create an account).
- Navigate to Settings › Access Tokens (https://huggingface.co/settings/tokens).
- Click “New token”, select the "read" scope, and create the token.
- Copy the generated token and use it in the Authorization header: Authorization: Bearer .
2. Add them to .dlt/secrets.toml
[sources.hugging_face_datasets_source] api_token = "your_hf_user_token_here"
dlt reads this automatically at runtime — never hardcode tokens in your pipeline script. For production environments, see setting up credentials with dlt for environment variable and vault-based options.
How do I set up and run the pipeline?
Set up a virtual environment and install dlt:
uv venv && source .venv/bin/activate uv pip install "dlt[workspace]"
1. Install the dlt AI Workbench:
dlt ai init --agent <your-agent> # <agent>: claude | cursor | codex
This installs project rules, a secrets management skill, appropriate ignore files, and configures the dlt MCP server for your agent. Learn more →
2. Install the rest-api-pipeline toolkit:
dlt ai toolkit rest-api-pipeline install
This loads the skills and context about dlt the agent uses to build the pipeline iteratively, efficiently, and safely. The agent uses MCP tools to inspect credentials — it never needs to read your secrets.toml directly. Learn more →
3. Start LLM-assisted coding:
Use /find-source to load data from the Hugging Face Datasets API into DuckDB.
The rest-api-pipeline toolkit takes over from here — it reads relevant API documentation, presents you with options for which endpoints to load, and follows a structured workflow to scaffold, debug, and validate the pipeline step by step.
4. Run the pipeline:
python hugging_face_datasets_pipeline.py
If everything is configured correctly, you'll see output like this:
Pipeline hugging_face_datasets_pipeline load step completed in 0.26 seconds 1 load package(s) were loaded to destination duckdb and into dataset hugging_face_datasets_data The duckdb destination used duckdb:/hugging_face_datasets.duckdb location to store data Load package 1749667187.541553 is LOADED and contains no failed jobs
Inspect your pipeline and data:
dlt pipeline hugging_face_datasets_pipeline show
This opens the Pipeline Dashboard where you can verify pipeline state, load metrics, schema (tables, columns, types), and query the loaded data directly.
Python pipeline example
This example loads rows and parquet from the Hugging Face Datasets API into DuckDB. It mirrors the endpoint and data selector configuration from the table above:
import dlt from dlt.sources.rest_api import RESTAPIConfig, rest_api_resources @dlt.source def hugging_face_datasets_source(api_token=dlt.secrets.value): config: RESTAPIConfig = { "client": { "base_url": "https://datasets-server.huggingface.co", "auth": { "type": "bearer", "api_token": api_token, }, }, "resources": [ {"name": "rows", "endpoint": {"path": "rows?dataset={dataset}&config={config}&split={split}&offset={offset}&length={length}", "data_selector": "rows"}}, {"name": "parquet_files", "endpoint": {"path": "parquet?dataset={dataset}", "data_selector": "parquet_files"}} ], } yield from rest_api_resources(config) def get_data() -> None: pipeline = dlt.pipeline( pipeline_name="hugging_face_datasets_pipeline", destination="duckdb", dataset_name="hugging_face_datasets_data", ) load_info = pipeline.run(hugging_face_datasets_source()) print(load_info)
To add more endpoints, append entries from the resource table to the "resources" list using the same name, path, and data_selector pattern.
How do I query the loaded data?
Once the pipeline runs, dlt creates one table per resource. You can query with Python or SQL.
Python (pandas DataFrame):
import dlt data = dlt.pipeline("hugging_face_datasets_pipeline").dataset() sessions_df = data.rows.df() print(sessions_df.head())
SQL (DuckDB example):
SELECT * FROM hugging_face_datasets_data.rows LIMIT 10;
In a marimo or Jupyter notebook:
import dlt data = dlt.pipeline("hugging_face_datasets_pipeline").dataset() data.rows.df().head()
See how to explore your data in marimo Notebooks and how to query your data in Python with dataset.
What destinations can I load Hugging Face Datasets data to?
dlt supports loading into any of these destinations — only the destination parameter changes:
| Destination | Example value |
|---|---|
| DuckDB (local, default) | "duckdb" |
| PostgreSQL | "postgres" |
| BigQuery | "bigquery" |
| Snowflake | "snowflake" |
| Redshift | "redshift" |
| Databricks | "databricks" |
| Filesystem (S3, GCS, Azure) | "filesystem" |
Change the destination in dlt.pipeline(destination="snowflake") and add credentials in .dlt/secrets.toml. See the full destinations list.
Troubleshooting
Authentication failures
If you request gated or private datasets without an Authorization header containing a valid user token you'll receive an error JSON: {"error":"The dataset does not exist, or is not accessible without authentication (private or gated). Please check the spelling of the dataset name or retry with authentication."}. Fix: create/use a Hugging Face access token and pass it as Authorization: Bearer <TOKEN>.
Rate limits
All Hub API calls (including the datasets server) are subject to Hugging Face‑wide rate limits. Exceeding the limit returns HTTP 429 responses; implement exponential back‑off or upgrade your plan for higher limits.
Pagination and slice limits
Rows, search and filter endpoints return at most 100 rows per request (length <= 100). Use offset + length to page through data; responses contain num_rows_total, num_rows_per_page and a partial flag indicating incomplete slices.
Private/gated dataset access
Some datasets require additional permissions (gated or private). Ensure your token has proper read permissions and the account is authorized for the gated dataset.
Ensure that the API key is valid to avoid 401 Unauthorized errors. Also, verify endpoint paths and parameters to avoid 404 Not Found errors.
Next steps
Continue your data engineering journey with the other toolkits of the dltHub AI Workbench:
data-exploration— Build custom notebooks, charts, and dashboards for deeper analysis with marimo notebooks.dlthub-runtime— Deploy, schedule, and monitor your pipeline in production.
dlt ai toolkit data-exploration install dlt ai toolkit dlthub-runtime install
Was this page helpful?
Community Hub
Need more dlt context for Hugging Face Datasets?
Request dlt skills, commands, AGENT.md files, and AI-native context.