fsspec
fsspec (Filesystem Spec) is a Python library that provides a single, consistent interface for reading and writing files across local disks, cloud object stores, HTTP, and many other storage backends.
Overview
fsspec provides a unified, filesystem-like API in Python that abstracts over dozens of concrete storage backends — local disk, Amazon S3, Google Cloud Storage, Azure Blob Storage, HDFS, HTTP(S), FTP, and more — behind the same interface (open, ls, glob, exists, and so on). Rather than every library implementing its own S3 client, GCS client, etc., tools like pandas, Dask, Zarr, and PyArrow rely on fsspec so that a user can point them at s3://..., gs://..., or https://... paths and have the right backend selected automatically, given the appropriate optional dependency (s3fs, gcsfs, and so on) is installed.
Basic usage
Copy code
import fsspec
fs = fsspec.filesystem("s3")
files = fs.glob("my-bucket/data/*.parquet")
with fsspec.open("s3://my-bucket/data/orders.parquet", "rb") as f:
data = f.read()
fsspec and DuckDB
DuckDB has its own native, C++-implemented remote filesystem support through the httpfs extension, which covers HTTP(S), S3-compatible object storage, Azure, and Google Cloud Storage, and is generally the fastest option since it avoids the Python layer entirely. For filesystems that httpfs doesn't natively support, DuckDB's Python client can register any fsspec-compliant filesystem via duckdb.register_filesystem(), letting DuckDB query paths on things like Hugging Face Hub, WebHDFS, or other niche or third-party fsspec implementations.
Copy code
import duckdb
from fsspec import filesystem
duckdb.register_filesystem(filesystem("gcs"))
duckdb.sql("SELECT * FROM read_csv('gcs://my-bucket/file.csv')")
Because fsspec filesystems run through Python rather than DuckDB's native C++ I/O path, performance is typically lower than httpfs for the storage systems httpfs already supports directly.
Related terms
The httpfs extension is DuckDB's built-in module for reading and writing files directly over HTTP(S) and from S3-compatible object storage, Azure, and Google Cloud Storage, without downloading them first.
Object storage →Object storage is a data storage architecture that manages data as discrete objects — each with data, metadata, and a unique identifier — in a flat namespace, accessed over HTTP APIs rather than a traditional file system hierarchy.
HDFS →HDFS (Hadoop Distributed File System) is a distributed, block-based file system designed to store very large files reliably across clusters of commodity hardware, historically the primary storage layer for Hadoop-based big data systems.
Cloud Storage →Cloud storage refers to a model of data storage where digital information is kept on remote servers accessed through the internet, rather than on local hard…
Reading files in DuckDB →DuckDB can read CSV, Parquet, JSON, and other file formats directly with SQL table functions, whether the files are local, remote over HTTP/S3, or matched in bulk with a glob pattern.
storage layer →The storage layer refers to the component of a data system responsible for persistently storing and managing data.
FAQS
Prefer httpfs when it supports your storage system (S3, Azure, GCS, plain HTTP) — it's implemented natively in DuckDB and is faster. Reach for fsspec registration only when you need a filesystem httpfs doesn't cover.
