Files and Types
DataChain's type system is built on Pydantic. Every chain carries a schema, every column has a type, and custom models integrate automatically.
File Abstraction
File is the bridge between object storage and the data layer. Every chain begins with files: read_storage() produces a chain of File objects. File carries storage coordinates and provides methods to read content.
Storage Coordinates
File tracks everything needed to locate and identify a blob: source, path, version, etag, size, is_latest, and last_modified. This metadata is indexed by the Dataset DB and available for chain operations without touching the actual bytes.
Content Access
File inherits from DataModel (a Pydantic BaseModel subclass), so it participates in schemas, gets stored as columns, and flows through all chain operations.
Modality Types
File has specialized subclasses for each data modality. Each adds domain-specific methods while inheriting all of File's capabilities.
ImageFile: read() returns a PIL.Image.Image. get_info() returns Image metadata (width, height, format). save() supports format conversion.
VideoFile: get_frame(frame, video_stream_index=0) returns one frame reference with a timestamp estimated from FPS metadata. Pixel access may seek to a nearby keyframe and decode forward. get_frames(start, end, step, video_stream_index=0) yields VideoFrame objects with frame indexes, video stream indexes, and decoded frame timestamps when available, and is preferred for sequential frame reads. get_fragments(duration, start, end) yields VideoFragment time slices. get_info(video_stream_index=0) returns Video metadata (fps, duration, codec, resolution).
AudioFile: get_fragments(duration, start, end) yields AudioFragment chunks. get_info() returns Audio metadata (sample_rate, channels, duration, codec). save() supports format conversion.
Sub-File Units
Videos and audio tracks can be sliced into smaller units that are themselves DataModels:
Annotation Types
Built-in DataModels for annotation primitives: BBox, OBBox, Pose, Pose3D, Segment.
Annotation types compose naturally into Pydantic models:
DataModel and Custom Types
Use pydantic.BaseModel directly for custom types; DataChain accepts it natively:
For external Pydantic models (like Mistral's ChatCompletionResponse), register them explicitly: dc.DataModel.register(MistralResponse).
Core Classes
- DataChain: the core class for composing queries with 60+ methods
- DataModel: Pydantic base for structured types
- Column (aliased as
C): references a column by name for vectorized expressions - File, ImageFile, VideoFile, AudioFile, TextFile: storage-native file types
- BBox, OBBox, Pose, Pose3D, Segment: annotation types (in
datachain.model)