Reading Data
DataChain reads data from many sources and formats through a family of read_* entry points. Each returns a lazy chain: nothing executes until a terminal operation triggers it.
Storage Files
read_storage() connects to any supported storage provider and returns a chain of File objects. It is the primary entry point for unstructured data: images, video, audio, PDFs, text. Always include a trailing slash in bucket and prefix URIs.
The type= parameter selects the right File subclass (ImageFile, VideoFile, AudioFile, TextFile). Without it, files are plain File objects with binary access.
For public buckets, pass anon=True explicitly:
Structured Formats
DataChain reads CSV, JSON, and Parquet directly from storage. These entry points parse the format and produce chains with typed columns.
JMESPath is powerful for real-world JSON formats like COCO, where images, annotations, and categories live under different top-level keys. Each read_json() call with a different jmespath extracts one array, and you merge them together on shared IDs.
For complex JSON, auto-generate a Pydantic model from a sample file:
SQL Databases
read_database() connects to any SQLAlchemy-compatible database:
Supported databases include PostgreSQL, MySQL, SQLite, DuckDB, Snowflake, and anything else SQLAlchemy supports. Schema inference is automatic.
In-Memory Sources
For data already in Python:
Merging External Metadata
The most common real-world pattern: files live in storage, metadata lives in a sidecar format. Read both sources as chains and merge on a shared key.
JSON Sidecars
Each image has a matching .json file with annotations:
COCO Annotations
One JSON file contains multiple arrays, merged by ID:
CSV Labels
Storage Providers
Each provider uses standard credential locations by default. For non-default configurations, use client_config:
Cross-provider workflows work transparently: