DataChain
The DataChain class creates a data chain, which is a sequence of data manipulation
steps such as reading data from storages, running AI or LLM models or calling external
services API to validate or enrich data. See DataChain
for examples of how to create a chain.
ConnectionType
module-attribute
ConnectionType = (
str
| sqlalchemy.engine.URL
| sqlalchemy.engine.interfaces.Connectable
| sqlalchemy.engine.Engine
| sqlalchemy.engine.Connection
| sqlalchemy.orm.Session
| sqlite3.Connection
)
listings
listings(
session: Session | None = None,
in_memory: bool = False,
column: str = "listing",
**kwargs
) -> DataChain
Generate chain with list of cached listings. Listing is a special kind of dataset which has directory listing data of some underlying storage (e.g S3 bucket).
Source code in datachain/lib/dc/listings.py
read_csv
read_csv(
path: (
str
| PathLike[str]
| list[str]
| list[PathLike[str]]
),
delimiter: str | None = None,
header: bool = True,
output: OutputType = None,
column: str = "",
model_name: str = "",
source: bool = True,
nrows: int | None = None,
session: Session | None = None,
settings: dict | None = None,
column_types: dict[str, str | DataType] | None = None,
parse_options: (
dict[str, str | bool | Callable] | None
) = None,
**kwargs
) -> DataChain
Generate chain from csv files.
Parameters:
-
path(str | PathLike[str] | list[str] | list[PathLike[str]]) –Storage URI with directory. URI must start with storage prefix such as
s3://,gs://,az://or "file:///". -
delimiter(str | None, default:None) –Character for delimiting columns. Takes precedence if also specified in
parse_options. Defaults to ",". -
header(bool, default:True) –Whether the files include a header row.
-
output(OutputType, default:None) –Dictionary or feature class defining column names and their corresponding types. List of column names is also accepted, in which case types will be inferred.
-
column(str, default:'') –Created column name.
-
model_name(str, default:'') –Generated model name.
-
source(bool, default:True) –Whether to include info about the source file.
-
nrows(int | None, default:None) –Optional row limit.
-
session(Session | None, default:None) –Session to use for the chain.
-
settings(dict | None, default:None) –Settings to use for the chain.
-
column_types(dict[str, str | DataType] | None, default:None) –Dictionary of column names and their corresponding types. It is passed to CSV reader and for each column specified type auto inference is disabled.
-
parse_options(dict[str, str | bool | Callable] | None, default:None) –Tells the parser how to process lines. See https://arrow.apache.org/docs/python/generated/pyarrow.csv.ParseOptions.html
Example
Reading a csv file:
Reading csv files from a directory as a combined dataset:
Source code in datachain/lib/dc/csv.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
read_dataset
read_dataset(
name: str,
namespace: str | None = None,
project: str | None = None,
version: str | int | None = None,
session: Session | None = None,
settings: dict | None = None,
delta: bool | None = False,
delta_on: str | Sequence[str] | None = (
"file.path",
"file.etag",
"file.version",
),
delta_result_on: str | Sequence[str] | None = None,
delta_compare: str | Sequence[str] | None = None,
delta_retry: bool | str | None = None,
delta_unsafe: bool = False,
update: bool = False,
) -> DataChain
Get data from a saved Dataset. It returns the chain itself. If dataset or version is not found locally, it will try to pull it from Studio.
Parameters:
-
name(str) –The dataset name, which can be a fully qualified name including the namespace and project. Alternatively, it can be a regular name, in which case the explicitly defined namespace and project will be used if they are set; otherwise, default values will be applied. The name can also include a version using the
name@versionformat (e.g."my_dataset@1.0.0"). Ifversionis also provided explicitly, it takes priority. -
namespace(str | None, default:None) –optional name of namespace in which dataset to read is created
-
project(str | None, default:None) –optional name of project in which dataset to read is created
-
version(str | int | None, default:None) –dataset version. Supports: - Exact version strings: "1.2.3" - Legacy integer versions: 1, 2, 3 (finds latest major version) - Version specifiers (PEP 440): ">=1.0.0,<2.0.0", "~=1.4.2", "==1.2.*", etc.
-
session(Session | None, default:None) –Session to use for the chain.
-
settings(dict | None, default:None) –Settings to use for the chain.
-
delta(bool | None, default:False) –If True, only process new or changed files instead of reprocessing everything. This saves time by skipping files that were already processed in previous versions. The optimization is working when a new version of the dataset is created. Default is False.
-
delta_on(str | Sequence[str] | None, default:('file.path', 'file.etag', 'file.version')) –Field(s) that uniquely identify each record in the source data. Used to detect which records are new or changed. Default is ("file.path", "file.etag", "file.version").
-
delta_result_on(str | Sequence[str] | None, default:None) –Field(s) in the result dataset that match
delta_onfields. Only needed if you rename the identifying fields during processing. Default is None. -
delta_compare(str | Sequence[str] | None, default:None) –Field(s) used to detect if a record has changed. If not specified, all fields except
delta_onfields are used. Default is None. -
delta_retry(bool | str | None, default:None) –Controls retry behavior for failed records: - String (field name): Reprocess records where this field is not empty (error mode) - True: Reprocess records missing from the result dataset (missing mode) - None: No retry processing (default)
-
update(bool, default:False) –If True always checks for newer versions available on Studio, even if some version of the dataset exists locally already. If False (default), it will only fetch the dataset from Studio if it is not found locally.
-
delta_unsafe(bool, default:False) –Allow restricted ops in delta: merge, union, subtract, diff, file_diff, agg, group_by, distinct. When multiple delta sources participate in one composed query, this must be enabled on every participating delta source.
Example
# Version can also be embedded in the name using the @ syntax
chain = dc.read_dataset("my_cats@1.0.0")
# Legacy integer version support (finds latest in major version)
chain = dc.read_dataset("my_cats", version=1) # Latest 1.x.x version
Source code in datachain/lib/dc/datasets.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | |
read_hf
read_hf(
dataset: HFDatasetType,
*args: Any,
session: Session | None = None,
settings: dict | None = None,
column: str = "",
model_name: str = "",
limit: int = 0,
**kwargs: Any
) -> DataChain
Generate chain from Hugging Face Hub dataset.
Parameters:
-
dataset(HFDatasetType) –Path or name of the dataset to read from Hugging Face Hub, or an instance of
datasets.Dataset-like object. -
args(Any, default:()) –Additional positional arguments to pass to
datasets.load_dataset. -
session(Session | None, default:None) –Session to use for the chain.
-
settings(dict | None, default:None) –Settings to use for the chain.
-
column(str, default:'') –Generated object column name.
-
model_name(str, default:'') –Generated model name.
-
limit(int, default:0) –The maximum number of items to read from the HF dataset. Applies
take(limit)todatasets.load_dataset. Defaults to 0 (no limit). -
kwargs(Any, default:{}) –Parameters to pass to
datasets.load_dataset.
Example
Load from Hugging Face Hub:
Generate chain from loaded dataset:
from datasets import load_dataset
ds = load_dataset("beans", split="train")
import datachain as dc
chain = dc.read_hf(ds)
Streaming with limit, for large datasets:
or use HF split syntax (not supported if streaming is enabled):
Source code in datachain/lib/dc/hf.py
read_json
read_json(
path: str | PathLike[str],
type: FileType = "text",
spec: DataType | None = None,
schema_from: str | None = "auto",
jmespath: str | None = None,
column: str | None = "",
model_name: str | None = None,
format: str | None = "json",
nrows: int | None = None,
**kwargs
) -> DataChain
Get data from JSON. It returns the chain itself.
Parameters:
-
path(str | PathLike[str]) –storage URI with directory. URI must start with storage prefix such as
s3://,gs://,az://or "file:///" -
type(FileType, default:'text') –read file as "binary", "text", or "image" data. Default is "text".
-
spec(DataType | None, default:None) –optional Data Model
-
schema_from(str | None, default:'auto') –path to sample to infer spec (if schema not provided)
-
column(str | None, default:'') –generated column name
-
model_name(str | None, default:None) –optional generated model name
-
format(str | None, default:'json') –"json", "jsonl"
-
jmespath(str | None, default:None) –optional JMESPATH expression to reduce JSON
-
nrows(int | None, default:None) –optional row limit for jsonl and JSON arrays
Example
infer JSON schema from data, reduce using JMESPATH
infer JSON schema from a particular path
Source code in datachain/lib/dc/json.py
read_pandas
read_pandas(
df: DataFrame,
name: str = "",
session: Session | None = None,
settings: dict | None = None,
in_memory: bool = False,
column: str = "",
) -> DataChain
Generate chain from pandas data-frame.
Example
Source code in datachain/lib/dc/pandas.py
read_parquet
read_parquet(
path: (
str
| PathLike[str]
| list[str]
| list[PathLike[str]]
),
partitioning: Any = "hive",
output: dict[str, DataType] | None = None,
column: str = "",
model_name: str = "",
source: bool = True,
session: Session | None = None,
settings: dict | None = None,
**kwargs
) -> DataChain
Generate chain from parquet files.
Parameters:
-
path(str | PathLike[str] | list[str] | list[PathLike[str]]) –Storage path(s) or URI(s). Can be a local path or start with a storage prefix like
s3://,gs://,az://,hf://or "file:///". Supports glob patterns: -*: wildcard -**: recursive wildcard -?: single character -{a,b}: brace expansion list -{1..9}: brace numeric or alphabetic range -
partitioning(Any, default:'hive') –Any pyarrow partitioning schema.
-
output(dict[str, DataType] | None, default:None) –Dictionary defining column names and their corresponding types.
-
column(str, default:'') –Created column name.
-
model_name(str, default:'') –Generated model name.
-
source(bool, default:True) –Whether to include info about the source file.
-
session(Session | None, default:None) –Session to use for the chain.
-
settings(dict | None, default:None) –Settings to use for the chain.
Example
Reading a single file:
All files from a directory:
Only parquet files from a directory, and all it's subdirectories:
Using filename patterns - numeric, list, starting with zeros:
Source code in datachain/lib/dc/parquet.py
read_records
read_records(
to_insert: dict | Iterable[dict] | None,
schema: dict[str, DataType],
session: Session | None = None,
settings: dict | None = None,
in_memory: bool = False,
) -> DataChain
Create a DataChain from the provided records. This is a low-level function
that directly inserts records into the database. Unlike convenience functions
like read_values() or read_csv(), you have to provide the schema and records
explicitly.
Compare it with read_values() which infers schema automatically and is using
higher-level abstractions which makes it less efficient. E.g. read_values() cannot
handle large datasets efficiently since it needs to load all data into memory.
Parameters:
-
to_insert(dict | Iterable[dict] | None) –records to insert (empty list / None to create an empty chain). Can be a list, iterator, or generator. Iterators are processed lazily without loading all records into memory at once.
Each record must be a dictionary with keys matching the schema. Dictionary values can be: - Primitive types (str, int, etc.) - DataModel objects (automatically flattened to match schema) - Raw flattened data (e.g., {"person__name": "Alice", ...}) -
schema(dict[str, DataType]) –describes chain signals and their corresponding types.
Example
import datachain as dc
from datachain import DataModel
# Simple records with primitive types
records = [
{"name": "Alice", "age": 30},
{"name": "Bob", "age": 25}
]
chain = dc.read_records(records, schema={"name": str, "age": int})
# Complex records with DataModel objects (automatically flattened)
class Person(DataModel):
name: str
age: int
city: str
people = [
Person(name="Alice", age=30, city="NYC"),
Person(name="Bob", age=25, city="LA"),
]
records = [{"person": p} for p in people]
chain = dc.read_records(records, schema={"person": Person})
# Raw pre-flattened data (also works)
records = [
{"person__name": "Alice", "person__age": 30, "person__city": "NYC"},
{"person__name": "Bob", "person__age": 25, "person__city": "LA"},
]
chain = dc.read_records(records, schema={"person": Person})
# Using an iterator/generator for memory efficiency
def generate_records():
for i in range(1000000):
yield {"id": i, "value": i * 2}
chain = dc.read_records(generate_records(), schema={"id": int, "value": int})
Notes
This call blocks until all records are inserted, but iterators are processed in batches to avoid loading all data into memory at once.
Source code in datachain/lib/dc/records.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | |
read_storage
read_storage(
uri: (
str
| PathLike[str]
| list[str]
| list[PathLike[str]]
),
*,
type: FileType = "binary",
session: Session | None = None,
settings: dict | None = None,
in_memory: bool = False,
recursive: bool | None = True,
column: str = "file",
update: bool = False,
anon: bool | None = None,
delta: bool | None = False,
delta_on: str | Sequence[str] | None = (
"file.path",
"file.etag",
"file.version",
),
delta_result_on: str | Sequence[str] | None = None,
delta_compare: str | Sequence[str] | None = None,
delta_retry: bool | str | None = None,
delta_unsafe: bool = False,
client_config: dict | None = None
) -> DataChain
Get data from storage(s) as a list of file with all file attributes. It returns the chain itself as usual.
Parameters:
-
uri(str | PathLike[str] | list[str] | list[PathLike[str]]) –Storage path(s) or URI(s). Can be a local path or start with a storage prefix like
s3://,gs://,az://,hf://or "file:///". Supports glob patterns: -*: wildcard -**: recursive wildcard -?: single character -{a,b}: brace expansion list -{1..9}: brace numeric or alphabetic range -
type(FileType, default:'binary') –read file as "binary", "text", or "image" data. Default is "binary".
-
recursive(bool | None, default:True) –search recursively for the given path.
-
column(str, default:'file') –Column name that will contain File objects. Default is "file".
-
update(bool, default:False) –force storage reindexing. Default is False.
-
anon(bool | None, default:None) –If True, we will treat cloud bucket as public one.
-
client_config(dict | None, default:None) –Optional client configuration for the storage client.
-
delta(bool | None, default:False) –If True, only process new or changed files instead of reprocessing everything. This saves time by skipping files that were already processed in previous versions. The optimization is working when a new version of the dataset is created. Default is False.
-
delta_on(str | Sequence[str] | None, default:('file.path', 'file.etag', 'file.version')) –Field(s) that uniquely identify each record in the source data. Used to detect which records are new or changed. Default is ("file.path", "file.etag", "file.version").
-
delta_result_on(str | Sequence[str] | None, default:None) –Field(s) in the result dataset that match
delta_onfields. Only needed if you rename the identifying fields during processing. Default is None. -
delta_compare(str | Sequence[str] | None, default:None) –Field(s) used to detect if a record has changed. If not specified, all fields except
delta_onfields are used. Default is None. -
delta_retry(bool | str | None, default:None) –Controls retry behavior for failed records: - String (field name): Reprocess records where this field is not empty (error mode) - True: Reprocess records missing from the result dataset (missing mode) - None: No retry processing (default)
-
delta_unsafe(bool, default:False) –Allow restricted ops in delta: merge, union, subtract, diff, file_diff, agg, group_by, distinct. When multiple delta sources participate in one composed query, this must be enabled on every participating delta source. Caller must ensure datasets are consistent and not partially updated.
Returns:
-
DataChain(DataChain) –A DataChain object containing the file information.
Examples:
Simple call from s3:
Match all .json files recursively using glob pattern
Match image file extensions for directories with pattern
By ranges in filenames:
Multiple URIs:
With AWS S3-compatible storage:
dc.read_storage(
"s3://my-bucket/my-dir",
client_config = {"aws_endpoint_url": "<minio-endpoint-url>"}
)
Source code in datachain/lib/dc/storage.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 | |
read_zarr
read_zarr(
path: (
str
| PathLike[str]
| list[str]
| list[PathLike[str]]
),
column: str = "zarr",
session: Session | None = None,
settings: dict | None = None,
in_memory: bool = False,
**kwargs
) -> DataChain
Generate a chain with one row per Zarr store.
Unlike :func:read_storage, which emits one row per physical object, this
reader collapses every object under a store root into a single
:class:~datachain.lib.zarr.ZarrStore row. Stores are discovered using the
standard *.zarr naming convention.
Parameters:
-
path(str | PathLike[str] | list[str] | list[PathLike[str]]) –Storage path(s) or URI(s). Can be a local path or start with a storage prefix like
s3://,gs://,az://orfile://. Supports glob patterns. -
column(str, default:'zarr') –Created column name. Defaults to
"zarr". -
session(Session | None, default:None) –Session to use for the chain.
-
settings(dict | None, default:None) –Settings to use for the chain.
-
in_memory(bool, default:False) –If True, use an in-memory database.
Example
Source code in datachain/lib/dc/zarr.py
read_values
read_values(
ds_name: str = "",
session: Session | None = None,
settings: dict | None = None,
in_memory: bool = False,
output: OutputType = None,
column: str = "",
**fr_map
) -> DataChain
Generate chain from list of values.
Source code in datachain/lib/dc/values.py
read_database
read_database(
query: str | Executable,
connection: ConnectionType,
params: (
Sequence[Mapping[str, Any]]
| Mapping[str, Any]
| None
) = None,
*,
output: dict[str, DataType] | None = None,
session: Session | None = None,
settings: dict | None = None,
in_memory: bool = False,
infer_schema_length: int | None = 100
) -> DataChain
Read the results of a SQL query into a DataChain.
Parameters:
-
query(str | Executable) –The SQL query to execute. Can be a raw SQL string or a SQLAlchemy
Executableobject. -
connection(ConnectionType) –SQLAlchemy connectable, str, or a sqlite3 connection Using SQLAlchemy makes it possible to use any DB supported by that library. If a DBAPI2 object, only sqlite3 is supported. The user is responsible for engine disposal and connection closure for the SQLAlchemy connectable; str connections are closed automatically.
-
params(Sequence[Mapping[str, Any]] | Mapping[str, Any] | None, default:None) –Parameters to pass to execute method.
-
output(dict[str, DataType] | None, default:None) –A dictionary mapping column names to types, used to override the schema inferred from the query results.
-
session(Session | None, default:None) –Session to use for the chain.
-
settings(dict | None, default:None) –Settings to use for the chain.
-
in_memory(bool, default:False) –If True, creates an in-memory session. Defaults to False.
-
infer_schema_length(int | None, default:100) –The maximum number of rows to scan for inferring schema. If set to
None, the full data may be scanned. The rows used for schema inference are stored in memory, so large values can lead to high memory usage. Only applies if theoutputparameter is not set for the given column.
Examples:
Reading from a SQL query against a user-supplied connection:
query = "SELECT key, value FROM tbl"
chain = dc.read_database(query, connection, output={"value": float})
Load data from a SQLAlchemy driver/engine:
from sqlalchemy import create_engine
engine = create_engine("postgresql+psycopg://myuser:mypassword@localhost:5432/mydb")
chain = dc.read_database("select * from tbl", engine)
Load data from a parameterized SQLAlchemy query:
query = "SELECT key, value FROM tbl WHERE value > :value"
dc.read_database(query, engine, params={"value": 50})
Notes
- This function works with a variety of databases — including, but not limited to, SQLite, DuckDB, PostgreSQL, and Snowflake, provided the appropriate driver is installed.
- This call is blocking, and will execute the query and return once the results are saved.
Source code in datachain/lib/dc/database.py
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 | |
datasets
datasets(
session: Session | None = None,
settings: dict | None = None,
in_memory: bool = False,
column: str | None = None,
include_listing: bool = False,
studio: bool = False,
attrs: list[str] | None = None,
) -> DataChain
Generate chain with list of registered datasets.
Parameters:
-
session(Session | None, default:None) –Optional session instance. If not provided, uses default session.
-
settings(dict | None, default:None) –Optional dictionary of settings to configure the chain.
-
in_memory(bool, default:False) –If True, creates an in-memory session. Defaults to False.
-
column(str | None, default:None) –Name of the output column in the chain. Defaults to None which means no top level column will be created.
-
include_listing(bool, default:False) –If True, includes listing datasets. Defaults to False.
-
studio(bool, default:False) –If True, returns datasets from Studio only, otherwise returns all local datasets. Defaults to False.
-
attrs(list[str] | None, default:None) –Optional list of attributes to filter datasets on. It can be just attribute without value e.g "NLP", or attribute with value e.g "location=US". Attribute with value can also accept "" to target all that have specific name e.g "location="
Returns:
-
DataChain(DataChain) –A new DataChain instance containing dataset information.
Example
Source code in datachain/lib/dc/datasets.py
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 | |
delete_dataset
delete_dataset(
name: str,
namespace: str | None = None,
project: str | None = None,
version: str | None = None,
force: bool | None = False,
studio: bool | None = False,
session: Session | None = None,
in_memory: bool = False,
) -> None
Removes specific dataset version or all dataset versions, depending on a force flag.
The rows table is dropped but the version metadata is kept so the semver stays reserved and dependents can still resolve lineage.
Parameters:
-
name(str) –The dataset name, which can be a fully qualified name including the namespace and project. Alternatively, it can be a regular name, in which case the explicitly defined namespace and project will be used if they are set; otherwise, default values will be applied.
-
namespace(str | None, default:None) –optional name of namespace in which dataset to delete is created
-
project(str | None, default:None) –optional name of project in which dataset to delete is created
-
version(str | None, default:None) –Optional dataset version
-
force(bool | None, default:False) –If true, all datasets versions will be removed. Defaults to False.
-
studio(bool | None, default:False) –If True, removes dataset from Studio only, otherwise removes local dataset. Defaults to False.
-
session(Session | None, default:None) –Optional session instance. If not provided, uses default session.
-
in_memory(bool, default:False) –If True, creates an in-memory session. Defaults to False.
Returns: None
Example
Source code in datachain/lib/dc/datasets.py
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 | |
move_dataset
move_dataset(
src: str,
dest: str,
session: Session | None = None,
in_memory: bool = False,
) -> None
Moves an entire dataset between namespaces and projects.
Parameters:
-
src(str) –The source dataset name. This can be a fully qualified name that includes the namespace and project, or a regular name. If a regular name is used, default values will be applied. The source dataset will no longer exist after the move.
-
dest(str) –The destination dataset name. This can also be a fully qualified name with a namespace and project, or just a regular name (default values will be used in that case). The original dataset will be moved here.
-
session(Session | None, default:None) –An optional session instance. If not provided, the default session will be used.
-
in_memory(bool, default:False) –If True, creates an in-memory session. Defaults to False.
Returns:
-
None–None
Examples:
Source code in datachain/lib/dc/datasets.py
delete_namespace
Removes a namespace by name.
Raises:
-
NamespaceNotFoundError–If the namespace does not exist.
-
NamespaceDeleteNotAllowedError–If the namespace is non-empty, is the default namespace, or is a system namespace, as these cannot be removed.
Parameters:
-
name(str) –The name of the namespace.
-
session(Session | None, default:None) –Session to use for getting project.
Source code in datachain/lib/namespaces.py
is_studio
is_studio() -> bool
is_local
is_local() -> bool
Column
Bases: ColumnClause
Source code in datachain/query/schema.py
glob
ColumnExpr
A column expression - either a Column reference
like C("file.size") or any arithmetic or comparison expression built from columns.
DataChainSchema
Dict-like public view of a DataChain schema.
Top-level schema fields are available through the standard dict API.
Use :meth:flatten for leaf columns and :meth:to_string for the printable
tree format.
Source code in datachain/lib/dc/datachain.py
__str__
__str__() -> str
flatten
Return flattened leaf column names and their types.
Parameters:
-
include_hidden(bool, default:True) –Whether to include hidden fields from complex signals.
Source code in datachain/lib/dc/datachain.py
to_string
Return the schema as an indented tree.
Parameters:
-
include_hidden(bool, default:True) –Whether to include hidden fields from complex signals.
-
indent(int, default:2) –Number of spaces to indent nested fields.
Source code in datachain/lib/dc/datachain.py
DataChain
DataChain(
query: DatasetQuery,
settings: Settings,
signal_schema: SignalSchema,
setup: dict | None = None,
_sys: bool = False,
)
DataChain - a data structure for batch data processing and evaluation.
It represents a sequence of data manipulation steps such as reading data from storages, running AI or LLM models or calling external services API to validate or enrich data.
Data in DataChain is presented as Python classes with arbitrary set of fields,
including nested classes. The data classes have to inherit from DataModel class.
The supported set of field types include: majority of the type supported by the
underlyind library Pydantic.
See Also
read_storage("s3://my-bucket/my-dir/") - reading unstructured
data files from storages such as S3, gs or Azure ADLS.
DataChain.save("name") - saving to a dataset.
read_dataset("name") - reading from a dataset.
read_values(fib=[1, 2, 3, 5, 8]) - generating from values.
read_pandas(pd.DataFrame(...)) - generating from pandas.
read_json("file.json") - generating from json.
read_csv("file.csv") - generating from csv.
read_parquet("file.parquet") - generating from parquet.
Example
import os
from mistralai.client import MistralClient
from mistralai.models.chat_completion import ChatMessage
import datachain as dc
PROMPT = (
"Was this bot dialog successful? "
"Describe the 'result' as 'Yes' or 'No' in a short JSON"
)
model = "mistral-large-latest"
api_key = os.environ["MISTRAL_API_KEY"]
chain = (
dc.read_storage("gs://datachain-demo/chatbot-KiT/")
.limit(5)
.settings(cache=True, parallel=5)
.map(
mistral_response=lambda file: MistralClient(api_key=api_key)
.chat(
model=model,
response_format={"type": "json_object"},
messages=[
ChatMessage(role="user", content=f"{PROMPT}: {file.read()}")
],
)
.choices[0]
.message.content,
)
.persist()
)
try:
print(chain.select("mistral_response").results())
except Exception as e:
print(f"do you have the right Mistral API key? {e}")
Source code in datachain/lib/dc/datachain.py
delta_unsafe
property
delta_unsafe: bool
Returns True if the chain runs in unsafe "delta" update mode.
job
property
Get the job for this chain.
Returns the existing job if running in SaaS, or creates a new one if running locally.
schema
property
schema: DataChainSchema
Get a dict-like schema view of the chain.
The returned object maps top-level signal names to Python types and can also produce leaf-column views:
__iter__
Make DataChain objects iterable.
Yields:
-
tuple[DataValue, ...]–Yields tuples of all column values for each row.
Source code in datachain/lib/dc/datachain.py
__or__
agg
agg(
func: Callable | None = None,
partition_by: PartitionByType | None = None,
params: str | Sequence[str] | None = None,
output: OutputType = None,
**signal_map: Callable
) -> Self
Aggregate rows using partition_by statement and apply a function to the
groups of aggregated rows. The function needs to return new objects for each
group of the new rows. It returns a chain itself with new signals.
Input-output relationship: N:M
This method bears similarity to gen() and map(), employing a comparable set
of parameters, yet differs in two crucial aspects:
- The
partition_byparameter: This specifies the column name or a list of column names that determine the grouping criteria for aggregation. - Group-based UDF function input: Instead of individual rows, the function
receives a list of all rows within each group defined by
partition_by.
If partition_by is not set or is an empty list, all rows will be placed
into a single group.
Parameters:
-
func(Callable | None, default:None) –Function applied to each group of rows.
-
partition_by(PartitionByType | None, default:None) –Column name(s) to group by. If None, all rows go into one group.
-
params(str | Sequence[str] | None, default:None) –List of column names used as input for the function. Default is taken from function signature.
-
output(OutputType, default:None) –Dictionary defining new signals and their corresponding types. Default type is taken from function signature.
-
**signal_map(Callable, default:{}) –kwargs can be used to define
functogether with its return signal name in format ofagg(result_column=my_func).
Examples:
Basic aggregation with lambda function:
chain = chain.agg(
total=lambda category, amount: [sum(amount)],
output=float,
partition_by="category",
)
chain.save("new_dataset")
An alternative syntax, when you need to specify a more complex function:
# It automatically resolves which columns to pass to the function
# by looking at the function signature.
def agg_sum(
file: list[File], amount: list[float]
) -> Iterator[tuple[File, float]]:
yield file[0], sum(amount)
chain = chain.agg(
agg_sum,
output={"file": File, "total": float},
# Alternative syntax is to use `C` (short for Column) to specify
# a column name or a nested column, e.g. C("file.path").
partition_by=C("category"),
)
chain.save("new_dataset")
Using complex signals for partitioning (File or any Pydantic BaseModel):
def my_agg(files: list[File]) -> Iterator[tuple[File, int]]:
yield files[0], sum(f.size for f in files)
chain = chain.agg(
my_agg,
params=("file",),
output={"file": File, "total": int},
partition_by="file", # Column referring to all sub-columns of File
)
chain.save("new_dataset")
Aggregating all rows into a single group (when partition_by is not set):
chain = chain.agg(
total_size=lambda file, size: [sum(size)],
output=int,
# No partition_by specified - all rows go into one group
)
chain.save("new_dataset")
Multiple partition columns:
chain = chain.agg(
total=lambda category, subcategory, amount: [sum(amount)],
output=float,
partition_by=["category", "subcategory"],
)
chain.save("new_dataset")
Source code in datachain/lib/dc/datachain.py
1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 | |
apply
Apply any function to the chain.
Useful for reusing in a chain of operations.
Example
Source code in datachain/lib/dc/datachain.py
avg
avg(col: str) -> StandardType
Compute the average of a column.
Parameters:
-
col(str) –The column to compute the average for.
Returns:
-
StandardType–The average of the column values.
Source code in datachain/lib/dc/datachain.py
c
Returns Column instance attached to the current chain.
chunk
Split a chain into smaller chunks for e.g. parallelization.
Parameters:
Example
Note
Bear in mind that index is 0-indexed but total isn't.
Use 0/3, 1/3 and 2/3, not 1/3, 2/3 and 3/3.
Source code in datachain/lib/dc/datachain.py
clone
column
Returns Column instance with a type if name is found in current schema, otherwise raises an exception.
Source code in datachain/lib/dc/datachain.py
count
count() -> int
diff
diff(
other: DataChain,
on: str | Sequence[str],
right_on: str | Sequence[str] | None = None,
compare: str | Sequence[str] | None = None,
right_compare: str | Sequence[str] | None = None,
added: bool = True,
deleted: bool = True,
modified: bool = True,
same: bool = False,
status_col: str | None = None,
) -> DataChain
Calculate differences between two chains.
This method identifies records that are added, deleted, modified, or unchanged between two chains. It adds a status column with values: A=added, D=deleted, M=modified, S=same.
Parameters:
-
other(DataChain) –Chain to compare against.
-
on(str | Sequence[str]) –Column(s) to match records between chains.
-
right_on(str | Sequence[str] | None, default:None) –Column(s) in the other chain to match against. Defaults to
on. -
compare(str | Sequence[str] | None, default:None) –Column(s) to check for changes. If not specified,all columns are used.
-
right_compare(str | Sequence[str] | None, default:None) –Column(s) in the other chain to compare against. Defaults to values of
compare. -
added(bool, default:True) –Include records that exist in this chain but not in the other.
-
deleted(bool, default:True) –Include records that exist only in the other chain.
-
modified(bool, default:True) –Include records that exist in both but have different values.
-
same(bool, default:False) –Include records that are identical in both chains.
-
status_col(str, default:None) –Name for the status column showing differences.
Default behavior: By default, shows added, deleted, and modified records, but excludes unchanged records (same=False). Status column is not created.
Example
Source code in datachain/lib/dc/datachain.py
2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 | |
distinct
Removes duplicate rows based on uniqueness of some input column(s) i.e if rows are found with the same value of input column(s), only one row is left in the result set.
Source code in datachain/lib/dc/datachain.py
exec
explode
explode(
col: str,
model_name: str | None = None,
column: str | None = None,
schema_sample_size: int = 1,
) -> DataChain
Explodes a column containing JSON objects (dict or str DataChain type) into individual columns based on the schema of the JSON. Schema is inferred from the first row of the column.
Parameters:
-
col(str) –the name of the column containing JSON to be exploded.
-
model_name(str | None, default:None) –optional generated model name. By default generates the name automatically.
-
column(str | None, default:None) –optional generated column name. By default generates the name automatically.
-
schema_sample_size(int, default:1) –the number of rows to use for inferring the schema of the JSON (in case some fields are optional and it's not enough to analyze a single row).
Returns:
-
DataChain(DataChain) –A new DataChain instance with the new set of columns.
Source code in datachain/lib/dc/datachain.py
file_diff
file_diff(
other: DataChain,
on: str = "file",
right_on: str | None = None,
added: bool = True,
modified: bool = True,
deleted: bool = False,
same: bool = False,
status_col: str | None = None,
) -> DataChain
Calculate differences between two chains containing files.
This method is specifically designed for file chains. It uses file source
and path to match files, and file version and etag to detect changes.
Parameters:
-
other(DataChain) –Chain to compare against.
-
on(str, default:'file') –File column name in this chain. Default is "file".
-
right_on(str | None, default:None) –File column name in the other chain. Defaults to
on. -
added(bool, default:True) –Include files that exist in this chain but not in the other.
-
deleted(bool, default:False) –Include files that exist only in the other chain.
-
modified(bool, default:True) –Include files that exist in both but have different versions/etags.
-
same(bool, default:False) –Include files that are identical in both chains.
-
status_col(str, default:None) –Name for the status column showing differences (A=added, D=deleted, M=modified, S=same).
Default behavior: By default, includes only new files (added=True and modified=True). This is useful for incremental processing.
Example
Source code in datachain/lib/dc/datachain.py
2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 | |
filter
filter(*args: Any) -> Self
Filter the chain according to conditions.
Example
Basic usage with built-in operators
Using glob to match patterns (case-sensitive, shell-style wildcards)
Using like / ilike for SQL pattern matching with % and _
wildcards. like is case-sensitive; ilike is case-insensitive:
Using regexp for regular-expression matching. Case-sensitive by
default; prepend the (?i) inline flag for case-insensitive:
dc.filter(C("file.name").regexp(r"^IMG_\d+\.jpg$"))
dc.filter(C("file.name").regexp(r"(?i)^img_\d+\.jpg$"))
Using in to match lists
Using datachain.func
Combining filters with "or"
Combining filters with "and"
Combining filters with "not"
Quick reference for column-level filter operators:
| Operator | Wildcards / syntax | Case sensitive? |
|---|---|---|
glob(pattern) |
shell: *, ?, […] |
yes |
like(pattern) |
SQL: %, _ |
yes |
ilike(pattern) |
SQL: %, _ |
no |
regexp(pattern) |
regular expression | yes (use (?i)) |
in_(values) |
exact values | yes |
Source code in datachain/lib/dc/datachain.py
2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 | |
gen
gen(
func: Callable | Generator | None = None,
params: str | Sequence[str] | None = None,
output: OutputType = None,
**signal_map
) -> Self
Apply a function to each row to create new rows (with potentially new signals). The function needs to return a new objects for each of the new rows. It returns a chain itself with new signals.
Input-output relationship: 1:N
This method is similar to map(), uses the same list of parameters, but with
one key differences: It produces a sequence of rows for each input row (like
extracting multiple file records from a single tar file or bounding boxes from a
single image file).
Example
Source code in datachain/lib/dc/datachain.py
group_by
group_by(
*args: Any,
partition_by: (
str
| Func
| ColumnExpr
| Sequence[str | Func | ColumnExpr]
| None
) = None,
**kwargs: Func
) -> Self
Group rows by specified set of signals and return new signals with aggregated values.
The supported functions
count(), sum(), avg(), min(), max(), any_value(), collect(), concat()
Example
Using complex signals:
Source code in datachain/lib/dc/datachain.py
1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 | |
limit
limit(n: int) -> Self
Return the first n rows of the chain.
If the chain is unordered, which rows are returned is undefined.
If the chain has less than n rows, the whole chain is returned.
Parameters:
-
n(int) –Number of rows to return.
Source code in datachain/lib/dc/datachain.py
map
map(
func: Callable | None = None,
params: str | Sequence[str] | None = None,
output: OutputType = None,
**signal_map: Any
) -> Self
Apply a function to each row to create new signals. The function should return a new object for each row. It returns a chain itself with new signals.
Input-output relationship: 1:1
Parameters:
-
func(Callable | None, default:None) –Function applied to each row.
-
params(str | Sequence[str] | None, default:None) –List of column names used as input for the function. Default is taken from function signature.
-
output(OutputType, default:None) –Dictionary defining new signals and their corresponding types. Default type is taken from function signature. Default can be also taken from kwargs - **signal_map (see below). If signal name is defined using signal_map (see below) only a single type value can be used.
-
**signal_map(Any, default:{}) –kwargs can be used to define
functogether with its return signal name in format ofmap(my_sign=my_func). This helps define signal names and functions in a nicer way.
Example
Using signal_map and single type in output:
Using func and output as a map:
Source code in datachain/lib/dc/datachain.py
max
max(col: str) -> StandardType
Compute the maximum of a column.
Parameters:
-
col(str) –The column to compute the maximum for.
Returns:
-
StandardType–The maximum value in the column.
Source code in datachain/lib/dc/datachain.py
merge
merge(
right_ds: DataChain,
on: MergeColType | Sequence[MergeColType],
right_on: (
MergeColType | Sequence[MergeColType] | None
) = None,
inner=False,
full=False,
rname="right_",
) -> Self
Merge two chains based on the specified criteria.
Parameters:
-
right_ds(DataChain) –Chain to join with.
-
on(MergeColType | Sequence[MergeColType]) –Predicate ("column.name", C("column.name"), or Func) or list of Predicates to join on. If both chains have the same predicates then this predicate is enough for the join. Otherwise,
right_onparameter has to specify the predicates for the other chain. -
right_on(MergeColType | Sequence[MergeColType] | None, default:None) –Optional predicate or list of Predicates for the
right_dsto join. -
inner(bool, default:False) –Whether to run inner join or outer join.
-
full(bool, default:False) –Whether to run full outer join.
-
rname(str, default:'right_') –Name prefix for conflicting signal names.
Examples:
imgs.merge(captions,
on=func.path.file_stem(imgs.c("file.path")),
right_on=func.path.file_stem(captions.c("file.path"))
)
Source code in datachain/lib/dc/datachain.py
1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 | |
min
min(col: str) -> StandardType
Compute the minimum of a column.
Parameters:
-
col(str) –The column to compute the minimum for.
Returns:
-
StandardType–The minimum value in the column.
Source code in datachain/lib/dc/datachain.py
mutate
Create or modify signals based on existing signals.
This method is vectorized and more efficient compared to map(), and it does not extract or download any data from the internal database. However, it can only utilize predefined built-in functions and their combinations.
Supported functions
Numerical: +, -, *, /, rand(), avg(), count(), func(), greatest(), least(), max(), min(), sum() String: length(), split(), replace(), regexp_replace() Filename: name(), parent(), file_stem(), file_ext() Array: length(), sip_hash_64(), euclidean_distance(), cosine_distance() Window: row_number(), rank(), dense_rank(), first()
Example:
dc.mutate(
area=Column("image.height") * Column("image.width"),
extension=file_ext(Column("file.path")),
dist=cosine_distance(embedding_text, embedding_image)
)
Window function example:
window = func.window(partition_by="file.parent", order_by="file.size")
dc.mutate(
row_number=func.row_number().over(window),
)
This method can be also used to rename signals. If the Column("name") provided
as value for the new signal - the old signal will be dropped. Otherwise a new
signal is created. Exception, if the old signal is nested one (e.g.
C("file.path")), it will be kept to keep the object intact.
Example:
Source code in datachain/lib/dc/datachain.py
offset
offset(offset: int) -> Self
Return the results starting with the offset row.
If the chain is unordered, which rows are skipped in undefined.
If the chain has less than offset rows, the result is an empty chain.
Parameters:
-
offset(int) –Number of rows to skip.
Source code in datachain/lib/dc/datachain.py
order_by
order_by(*args, descending: bool = False) -> Self
Orders by specified set of columns.
Parameters:
-
descending(bool, default:False) –Whether to sort in descending order or not.
Note
Order is not guaranteed when steps are added after an order_by statement.
I.e. when using read_dataset an order_by statement should be used if
the order of the records in the chain is important.
Using order_by directly before limit, to_list and similar methods
will give expected results.
See https://github.com/datachain-ai/datachain/issues/477
for further details.
Source code in datachain/lib/dc/datachain.py
parse_tabular
parse_tabular(
output: OutputType = None,
column: str = "",
model_name: str = "",
source: bool = True,
nrows: int | None = None,
**kwargs: Any
) -> Self
Generate chain from list of tabular files.
Parameters:
-
output(OutputType, default:None) –Dictionary or feature class defining column names and their corresponding types. List of column names is also accepted, in which case types will be inferred.
-
column(str, default:'') –Generated column name.
-
model_name(str, default:'') –Generated model name.
-
source(bool, default:True) –Whether to include info about the source file.
-
nrows(int | None, default:None) –Optional row limit.
-
kwargs(Any, default:{}) –Parameters to pass to pyarrow.dataset.dataset.
Example
Reading a json lines file:
import datachain as dc
chain = dc.read_storage("s3://mybucket/file.jsonl")
chain = chain.parse_tabular(format="json")
Reading a filtered list of files as a dataset:
Source code in datachain/lib/dc/datachain.py
2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 | |
persist
Saves temporary chain that will be removed after the process ends. Temporary datasets are useful for optimization, for example when we have multiple chains starting with identical sub-chain. We can then persist that common chain and use it to calculate other chains, to avoid re-calculation every time. It returns the chain itself.
Source code in datachain/lib/dc/datachain.py
print_schema
print_schema(file: IO | None = None) -> None
Deprecated. Use print(chain.schema).
Source code in datachain/lib/dc/datachain.py
reset_settings
results
Return all rows, optionally built via row_factory.
Source code in datachain/lib/dc/datachain.py
sample
sample(n: int) -> Self
Return a random sample from the chain.
Parameters:
-
n(int) –Number of samples to draw.
Note
Samples are not deterministic, and streamed/paginated queries or multiple workers will draw samples with replacement.
Source code in datachain/lib/dc/datachain.py
save
save(
name: str,
version: str | None = None,
description: str | None = None,
attrs: list[str] | None = None,
update_version: str | None = "patch",
**kwargs
) -> DataChain
Save to a Dataset. It returns the chain itself.
Parameters:
-
name(str) –dataset name. This can be either a fully qualified name, including the namespace and project, or just a regular dataset name. In the latter case, the namespace and project will be taken from the settings (if specified) or from the default values otherwise.
-
version(str | None, default:None) –version of a dataset. If version is not specified and dataset already exists, version patch increment will happen e.g 1.2.1 -> 1.2.2.
-
description(str | None, default:None) –description of a dataset.
-
attrs(list[str] | None, default:None) –attributes of a dataset. They can be without value, e.g "NLP", or with a value, e.g "location=US".
-
update_version(str | None, default:'patch') –which part of the dataset version to automatically increase. Available values:
major,minororpatch. Default ispatch.
Source code in datachain/lib/dc/datachain.py
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 | |
select
Select only a specified set of signals.
Nested selections (e.g. "file.path") preserve the parent object by
generating partial models rather than flattening into standalone fields.
Example
Source code in datachain/lib/dc/datachain.py
select_except
Select all signals except the specified ones.
Supports excluding nested fields (e.g. "file.path"), in which case a
partial model is generated for the parent signal.
Source code in datachain/lib/dc/datachain.py
settings
settings(
cache: bool | None = None,
prefetch: bool | int | None = None,
parallel: bool | int | None = None,
workers: int | None = None,
namespace: str | None = None,
project: str | None = None,
min_task_size: int | None = None,
batch_size: int | None = None,
sys: bool | None = None,
ephemeral: bool | None = None,
) -> Self
Set chain execution parameters. Returns the chain itself, allowing method
chaining for subsequent operations. To restore all settings to their default
values, use reset_settings().
Parameters:
-
cache(bool | None, default:None) –Enable files caching to speed up subsequent accesses to the same files from the same or different chains. Defaults to False.
-
prefetch(bool | int | None, default:None) –Enable prefetching of files. This will download files in advance in parallel. If an integer is provided, it specifies the number of files to prefetch concurrently for each process on each worker. Defaults to 2. Set to 0 or False to disable prefetching.
-
parallel(bool | int | None, default:None) –Number of processes to use for processing user-defined functions (UDFs) in parallel. If an integer is provided, it specifies the number of CPUs to use. If True, all available CPUs are used. Defaults to 1.
-
namespace(str | None, default:None) –Namespace to use for the chain by default.
-
project(str | None, default:None) –Project to use for the chain by default.
-
min_task_size(int | None, default:None) –Minimum number of rows per worker/process for parallel processing by UDFs. Defaults to 1.
-
batch_size(int | None, default:None) –Number of rows per insert by UDF to fine tune and balance speed and memory usage. This might be useful when processing large rows or when running into memory issues. Defaults to 2000.
-
ephemeral(bool | None, default:None) –If True, no persistent objects are created in the metastore (no jobs, checkpoints, or datasets). UDF execution still uses temporary tables. Calling .save() in ephemeral mode will raise an error.
Example
Source code in datachain/lib/dc/datachain.py
setup
Setup variables to pass to UDF functions.
Use before running map/gen/agg to save an object and pass it as an argument to the UDF.
The value must be a callable (a lambda: <value> syntax can be used to quickly
create one) that returns the object to be passed to the UDF. It is evaluated
lazily when UDF is running, in case of multiple machines the callable is run on
a worker machine.
Example
import anthropic
from anthropic.types import Message
import datachain as dc
(
dc.read_storage(DATA, type="text")
.settings(parallel=4, cache=True)
# Setup Anthropic client and pass it to the UDF below automatically
# The value is callable (see the note above)
.setup(client=lambda: anthropic.Anthropic(api_key=API_KEY))
.map(
claude=lambda client, file: client.messages.create(
model=MODEL,
system=PROMPT,
messages=[{"role": "user", "content": file.get_value()}],
),
output=Message,
)
)
Source code in datachain/lib/dc/datachain.py
show
show(
limit: int = 20,
flatten: bool = False,
transpose: bool = False,
truncate: bool = True,
include_hidden: bool = False,
) -> None
Show a preview of the chain results.
Parameters:
-
limit(int, default:20) –How many rows to show.
-
flatten(bool, default:False) –Whether to use a multiindex or flatten column names.
-
transpose(bool, default:False) –Whether to transpose rows and columns.
-
truncate(bool, default:True) –Whether or not to truncate the contents of columns.
-
include_hidden(bool, default:False) –Whether to include hidden columns.
Source code in datachain/lib/dc/datachain.py
shuffle
Shuffle rows with a best-effort deterministic ordering.
This produces repeatable shuffles. Merge and union operations can lead to non-deterministic results. Use order by or save a dataset afterward to guarantee the same result.
Source code in datachain/lib/dc/datachain.py
similarity_search
similarity_search(
column: str,
query: Sequence[float],
*,
k: int | None = 10,
metric: str = "cosine",
score_column: str | None = None
) -> Self
Return rows whose column embedding is closest to query.
Shortcut for .mutate(...).order_by(...).limit(k).
Parameters:
-
column(str) –name of the embedding column on each row.
-
query(Sequence[float]) –reference embedding (the vector to compare against).
-
k(int | None, default:10) –how many closest rows to return.
Noneskips the limit and annotates/sorts every row. -
metric(str, default:'cosine') –"cosine","euclidean"or"l2"("l2"is an alias for"euclidean"). -
score_column(str | None, default:None) –name to store the distance under. If
None(default) the score is not included in the result.
Example
Source code in datachain/lib/dc/datachain.py
subtract
subtract(
other: DataChain,
on: str | Sequence[str] | None = None,
right_on: str | Sequence[str] | None = None,
) -> Self
Remove rows that appear in another chain.
Parameters:
-
other(DataChain) –chain whose rows will be removed from
self -
on(str | Sequence[str] | None, default:None) –columns to consider for determining row equality in
self. If unspecified, defaults to all common columns betweenselfandother. -
right_on(str | Sequence[str] | None, default:None) –columns to consider for determining row equality in
other. If unspecified, defaults to the same values ason.
Source code in datachain/lib/dc/datachain.py
1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 | |
sum
sum(col: str) -> StandardType
Compute the sum of a column.
Parameters:
-
col(str) –The column to compute the sum for.
Returns:
-
StandardType–The sum of the column values.
Source code in datachain/lib/dc/datachain.py
to_columnar_data_with_names
to_columnar_data_with_names(
chunk_size: int = DEFAULT_PARQUET_CHUNK_SIZE,
) -> tuple[list[str], Iterator[list[list[Any]]]]
Returns column names and the results as an iterator that provides chunks, with each chunk containing a list of columns, where each column contains a list of the row values for that column in that chunk. Useful for columnar data formats, such as parquet or other OLAP databases.
Source code in datachain/lib/dc/datachain.py
to_csv
to_csv(
path: str | PathLike[str],
delimiter: str = ",",
fs_kwargs: dict[str, Any] | None = None,
**kwargs
) -> File
Save chain to a csv (comma-separated values) file and return the stored
File.
Parameters:
-
path(str | PathLike[str]) –Path to save the file. This supports local paths as well as remote paths, such as s3:// or hf:// with fsspec.
-
delimiter(str, default:',') –Delimiter to use for the resulting file.
-
fs_kwargs(dict[str, Any] | None, default:None) –Optional kwargs forwarded to the underlying fsspec filesystem when writing (e.g., s3://, gs://, hf://), fsspec-specific options are supported.
Returns:
-
File(File) –The stored file with refreshed metadata (version, etag, size).
Source code in datachain/lib/dc/datachain.py
to_database
to_database(
table_name: str,
connection: ConnectionType,
*,
batch_size: int = DEFAULT_DATABASE_BATCH_SIZE,
on_conflict: str | None = None,
conflict_columns: list[str] | None = None,
column_mapping: dict[str, str | None] | None = None
) -> int
Save chain to a database table using a given database connection.
This method exports all DataChain records to a database table, creating the table if it doesn't exist and appending data if it does. The table schema is automatically inferred from the DataChain's signal schema.
For PostgreSQL, tables are created in the schema specified by the connection's search_path (defaults to 'public'). Use URL parameters to target specific schemas.
Parameters:
-
table_name(str) –Name of the database table to create/write to.
-
connection(ConnectionType) –SQLAlchemy connectable, str, or a sqlite3 connection Using SQLAlchemy makes it possible to use any DB supported by that library. If a DBAPI2 object, only sqlite3 is supported. The user is responsible for engine disposal and connection closure for the SQLAlchemy connectable; str connections are closed automatically.
-
batch_size(int, default:DEFAULT_DATABASE_BATCH_SIZE) –Number of rows to insert per batch for optimal performance. Larger batches are faster but use more memory. Default: 10,000.
-
on_conflict(str | None, default:None) –Strategy for handling duplicate rows (requires table constraints): - None: Raise error (
sqlalchemy.exc.IntegrityError) on conflict (default) - "ignore": Skip duplicate rows silently - "update": Update existing rows with new values -
conflict_columns(list[str] | None, default:None) –List of column names that form a unique constraint for conflict resolution. Required when on_conflict='update' and using PostgreSQL.
-
column_mapping(dict[str, str | None] | None, default:None) –Optional mapping to rename or skip columns: - Dict mapping DataChain column names to database column names - Set values to None to skip columns entirely, or use
defaultdictto skip all columns except those specified.
Returns:
-
int(int) –Number of rows affected (inserted/updated). -1 if DB driver doesn't support telemetry.
Examples:
Basic usage with PostgreSQL:
import datachain as dc
rows_affected = (dc
.read_storage("s3://my-bucket/")
.to_database("files_table", "postgresql://user:pass@localhost/mydb")
)
print(f"Inserted/updated {rows_affected} rows")
Using SQLite with connection string:
rows_affected = chain.to_database("my_table", "sqlite:///data.db")
print(f"Affected {rows_affected} rows")
Column mapping and renaming:
mapping = {
"user.id": "id",
"user.name": "name",
"user.password": None # Skip this column
}
chain.to_database("users", engine, column_mapping=mapping)
Handling conflicts (requires PRIMARY KEY or UNIQUE constraints):
# Skip duplicates
chain.to_database("my_table", engine, on_conflict="ignore")
# Update existing records
chain.to_database(
"my_table", engine, on_conflict="update", conflict_columns=["id"]
)
Working with different databases:
# MySQL
mysql_engine = sa.create_engine("mysql+pymysql://user:pass@host/db")
chain.to_database("mysql_table", mysql_engine)
# SQLite in-memory
chain.to_database("temp_table", "sqlite:///:memory:")
PostgreSQL with schema support:
pg_url = "postgresql://user:pass@host/db?options=-c search_path=analytics"
chain.to_database("processed_data", pg_url)
Source code in datachain/lib/dc/datachain.py
2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 | |
to_iter
Yields rows of values, optionally limited to the specified columns.
Parameters:
-
*cols(str | Column, default:()) –Limit to the specified columns. String names and plain
C("...")column references are supported. By default, all columns are selected.
Yields:
Example
Iterating over all rows:
DataChain is iterable and can be used in a for loop directly which is
equivalent to ds.to_iter():
Iterating over all rows with selected columns:
Iterating over a single column:
Source code in datachain/lib/dc/datachain.py
to_json
to_json(
path: str | PathLike[str],
fs_kwargs: dict[str, Any] | None = None,
include_outer_list: bool = True,
) -> File
Save chain to a JSON file and return the stored File.
Parameters:
-
path(str | PathLike[str]) –Path to save the file. This supports local paths as well as remote paths, such as s3:// or hf:// with fsspec.
-
fs_kwargs(dict[str, Any] | None, default:None) –Optional kwargs forwarded to the underlying fsspec filesystem when writing (e.g., s3://, gs://, hf://), fsspec-specific options are supported.
-
include_outer_list(bool, default:True) –Sets whether to include an outer list for all rows. Setting this to True makes the file valid JSON, while False instead writes in the JSON lines format.
Returns:
-
File(File) –The stored file with refreshed metadata (version, etag, size).
Source code in datachain/lib/dc/datachain.py
to_jsonl
Save chain to a JSON lines file.
Parameters:
-
path(str | PathLike[str]) –Path to save the file. This supports local paths as well as remote paths, such as s3:// or hf:// with fsspec.
-
fs_kwargs(dict[str, Any] | None, default:None) –Optional kwargs forwarded to the underlying fsspec filesystem when writing (e.g., s3://, gs://, hf://), fsspec-specific options are supported.
Returns:
-
File(File) –The stored file with refreshed metadata (version, etag, size).
Source code in datachain/lib/dc/datachain.py
to_list
Returns a list of rows of values, optionally limited to the specified columns.
Parameters:
-
*cols(str | Column, default:()) –Limit to the specified columns. String names and plain
C("...")column references are supported. By default, all columns are selected.
Returns:
-
list[tuple[DataValue, ...]]–list[tuple[DataType, ...]]: Returns a list of tuples of items for each row.
Example
Getting all rows as a list:
Getting all rows with selected columns as a list:
Getting a single column as a list:
Source code in datachain/lib/dc/datachain.py
to_pandas
to_pandas(
flatten: bool = False,
include_hidden: bool = True,
as_object: bool = False,
) -> DataFrame
Return a pandas DataFrame from the chain.
Parameters:
-
flatten(bool, default:False) –Whether to use a multiindex or flatten column names.
-
include_hidden(bool, default:True) –Whether to include hidden columns.
-
as_object(bool, default:False) –Whether to emit a dataframe backed by Python objects rather than pandas-inferred dtypes.
Returns:
-
DataFrame–pd.DataFrame: A pandas DataFrame representation of the chain.
Source code in datachain/lib/dc/datachain.py
to_parquet
to_parquet(
path: str | PathLike[str] | BinaryIO,
partition_cols: Sequence[str] | None = None,
chunk_size: int = DEFAULT_PARQUET_CHUNK_SIZE,
fs_kwargs: dict[str, Any] | None = None,
**kwargs
) -> None
Save chain to parquet file with SignalSchema metadata.
Parameters:
-
path(str | PathLike[str] | BinaryIO) –Path or a file-like binary object to save the file. This supports local paths as well as remote paths, such as s3:// or hf:// with fsspec.
-
partition_cols(Sequence[str] | None, default:None) –Column names by which to partition the dataset.
-
chunk_size(int, default:DEFAULT_PARQUET_CHUNK_SIZE) –The chunk size of results to read and convert to columnar data, to avoid running out of memory.
-
fs_kwargs(dict[str, Any] | None, default:None) –Optional kwargs forwarded to the underlying fsspec filesystem when writing (e.g., s3://, gs://, hf://), fsspec-specific options are supported.
Source code in datachain/lib/dc/datachain.py
2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 | |
to_pytorch
to_pytorch(
transform=None,
tokenizer=None,
tokenizer_kwargs=None,
num_samples=0,
remove_prefetched: bool = False,
)
Convert to pytorch dataset format.
Parameters:
-
transform(Transform, default:None) –Torchvision transforms to apply to the dataset.
-
tokenizer(Callable, default:None) –Tokenizer to use to tokenize text values.
-
tokenizer_kwargs(dict, default:None) –Additional kwargs to pass when calling tokenizer.
-
num_samples(int, default:0) –Number of random samples to draw for each epoch. This argument is ignored if
num_samples=0(the default). -
remove_prefetched(bool, default:False) –Whether to remove prefetched files after reading.
Example
Source code in datachain/lib/dc/datachain.py
to_records
Convert every row to a dictionary.
Source code in datachain/lib/dc/datachain.py
to_storage
to_storage(
output: str | PathLike[str],
signal: str = "file",
placement: ExportPlacement = "fullpath",
link_type: Literal["copy", "symlink"] = "copy",
num_threads: int | None = EXPORT_FILES_MAX_THREADS,
anon: bool | None = None,
client_config: dict | None = None,
) -> None
Export files from a specified signal to a directory. Files can be exported to a local or cloud directory.
Parameters:
-
output(str | PathLike[str]) –Path to the target directory for exporting files.
-
signal(str, default:'file') –Name of the signal to export files from.
-
placement(ExportPlacement, default:'fullpath') –The method to use for naming exported files. The possible values are: "filename", "etag", "fullpath", "filepath", and "checksum". Example path translations for an object located at
s3://bucket/data/img.jpgand exported to./out:- "filename" ->
./out/img.jpg(no directories) - "filepath" ->
./out/data/img.jpg(relative path kept) - "fullpath" ->
./out/bucket/data/img.jpg(remote host kept) - "etag" ->
./out/<etag>.jpg(unique name via object digest)
Local sources behave like "filepath" for "fullpath" placement. Relative destinations such as "." or ".." and absolute paths are supported for every strategy.
- "filename" ->
-
link_type(Literal['copy', 'symlink'], default:'copy') –Method to use for exporting files. Falls back to
'copy'if symlinking fails. -
num_threads(int | None, default:EXPORT_FILES_MAX_THREADS) –number of threads to use for exporting files. By default, it uses 5 threads.
-
anon(bool | None, default:None) –If True, we will treat cloud bucket as a public one. Default behavior depends on the previous session configuration (e.g. happens in the initial
read_storage) and particular cloud storage client implementation (e.g. S3 fallbacks to anonymous access if no credentials were found). -
client_config(dict | None, default:None) –Optional configuration for the destination storage client
Example
Cross cloud transfer
Source code in datachain/lib/dc/datachain.py
2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 | |
to_values
Returns a flat list of values from a single column.
Parameters:
-
col(str | Column) –The column to extract values from. String names and plain
C("...")column references are supported.
Returns:
-
list[DataValue]–list[DataValue]: Returns a flat list of values from the specified column.
Example
Getting all values from a single column:
Getting all file sizes:
Source code in datachain/lib/dc/datachain.py
union
Return the set union of the two datasets.
Parameters:
-
other(Self) –chain whose rows will be added to
self.
Source code in datachain/lib/dc/datachain.py
DataChainError
Bases: Exception
Session
Session(
name="",
catalog: Catalog | None = None,
client_config: dict | None = None,
in_memory: bool = False,
)
Session is a context that keeps track of temporary DataChain datasets for a proper cleanup. By default, a global session is created.
Temporary or ephemeral datasets are the ones created without specified name. They are useful for optimization purposes and should be automatically removed.
Temp dataset has specific name format
"session_
The
Temp dataset examples
session_myname_624b41_48e8b4 session_4b962d_2a5dff
Parameters:
name (str): The name of the session. Only latters and numbers are supported. It can be empty. catalog (Catalog): Catalog object.
Source code in datachain/query/session.py
get
classmethod
get(
session: Session | None = None,
catalog: Catalog | None = None,
client_config: dict | None = None,
in_memory: bool = False,
) -> Session
Creates a Session() object from a catalog.
Parameters:
-
session(Session, default:None) –Optional Session(). If not provided a new session will be created. It's needed mostly for simple API purposes.
-
catalog(Catalog, default:None) –Optional catalog. By default, a new catalog is created.
Source code in datachain/query/session.py
get_job
Return the current job if one exists, without creating a new one.
Checks the cached _CURRENT_JOB and DATACHAIN_JOB_ID env var.
Returns None if no job is found.
Source code in datachain/query/session.py
get_or_create_job
Get or create a Job for this process.
Returns:
-
Job(Job) –The active Job instance.
Behavior
- If a job already exists, it is returned.
- If in Studio without DATACHAIN_JOB_ID, raises an error.
- If
DATACHAIN_JOB_IDis set, the corresponding job is fetched. - Otherwise, a new job is created:
- Name = absolute path to the Python script.
- Query = empty string.
- Parent = last job with the same name, if available.
- Status = "running". Exit hooks are registered to finalize the job.
Note
Job is shared across all Session instances to ensure one job per process.
Source code in datachain/query/session.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | |