Skip to content

DataCatalog

kedro.io.DataCatalog

DataCatalog(datasets=None, config_resolver=None, load_versions=None, save_version=None, validation_enabled=True)

Bases: CatalogProtocol

A centralized registry for managing datasets in a Kedro project.

The DataCatalog provides a unified interface for loading and saving datasets, enabling seamless interaction with various data sources and formats. It supports features such as lazy loading, versioning, and dynamic dataset creation using dataset factory patterns.

This class is the core component of Kedro's data management system, allowing datasets to be defined, accessed, and manipulated in a consistent and reusable way.

Attributes:

  • default_runtime_patterns (ClassVar) –

    A dictionary defining the default runtime pattern for datasets of type kedro.io.MemoryDataset.

  • _datasets (dict[str, AbstractDataset]) –

    A dictionary of fully initialized datasets.

  • _lazy_datasets (dict[str, _LazyDataset]) –

    A dictionary of _LazyDataset instances for deferred initialization.

  • _load_versions (dict[str, _LazyDataset]) –

    A mapping of dataset names to specific versions to load.

  • _save_version (dict[str, _LazyDataset]) –

    The global version string for saving datasets.

  • _config_resolver –

    Resolves dataset factory patterns and configurations.

Example:

    from kedro.io import DataCatalog, MemoryDataset

    # Define datasets
    datasets = {
        "cars": MemoryDataset(data={"type": "car", "capacity": 5}),
        "planes": MemoryDataset(data={"type": "jet", "capacity": 200}),
    }

    # Initialize the catalog
    catalog = DataCatalog(datasets=datasets)

    # Load data
    cars_data = catalog.load("cars")
    print(cars_data)

    # Save data
    catalog.save("planes", {"type": "propeller", "capacity": 100})
    planes_data = catalog.load("planes")
    print(planes_data)

This catalog combines datasets passed directly via the datasets argument and dynamic datasets resolved from config (e.g., from YAML).

If a dataset name is present in both datasets and the resolved config, the dataset from datasets takes precedence. A warning is logged, and the config-defined dataset is skipped and removed from the internal config.

Parameters:

  • datasets (dict[str, AbstractDataset] | None, default: None ) –

    A dictionary of dataset names and dataset instances.

  • config_resolver (CatalogConfigResolver | None, default: None ) –

    An instance of CatalogConfigResolver to resolve dataset factory patterns and configurations.

  • load_versions (dict[str, str] | None, default: None ) –

    A mapping between dataset names and versions to load. Has no effect on datasets without enabled versioning.

  • save_version (str | None, default: None ) –

    Version string to be used for save operations by all datasets with enabled versioning. It must: a) be a case-insensitive string that conforms with operating system filename limitations, b) always return the latest version when sorted in lexicographical order.

  • validation_enabled (bool, default: True ) –

    Whether dataset validation (declared via the validator key in catalog entries) is applied on load and save. The KEDRO_DATASET_VALIDATION environment variable, when set, takes precedence over this flag.

Example:

    from kedro.io import DataCatalog, MemoryDataset
    from kedro_datasets.pandas import CSVDataset

    # Define datasets
    datasets = {
        "cars": CSVDataset(filepath="cars.csv"),
        "planes": MemoryDataset(data={"type": "jet", "capacity": 200}),
    }

    # Initialize the catalog
    catalog = DataCatalog(
        datasets=datasets,
        load_versions={"cars": "2023-01-01T00.00.00"},
        save_version="2023-01-02T00.00.00",
    )

    print(catalog)

Source code in kedro/io/data_catalog.py
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
def __init__(
    self,
    datasets: dict[str, AbstractDataset] | None = None,
    config_resolver: CatalogConfigResolver | None = None,
    load_versions: dict[str, str] | None = None,
    save_version: str | None = None,
    validation_enabled: bool = True,
) -> None:
    """Initializes a ``DataCatalog`` to manage datasets with loading, saving, and versioning capabilities.

    This catalog combines datasets passed directly via the `datasets` argument and dynamic datasets
    resolved from config (e.g., from YAML).

    If a dataset name is present in both `datasets` and the resolved config, the dataset from `datasets`
    takes precedence. A warning is logged, and the config-defined dataset is skipped and removed from
    the internal config.

    Args:
        datasets: A dictionary of dataset names and dataset instances.
        config_resolver: An instance of CatalogConfigResolver to resolve dataset factory patterns and configurations.
        load_versions: A mapping between dataset names and versions
            to load. Has no effect on datasets without enabled versioning.
        save_version: Version string to be used for ``save`` operations
            by all datasets with enabled versioning. It must: a) be a
            case-insensitive string that conforms with operating system
            filename limitations, b) always return the latest version when
            sorted in lexicographical order.
        validation_enabled: Whether dataset validation (declared via the
            `validator` key in catalog entries) is applied on load and
            save. The `KEDRO_DATASET_VALIDATION` environment variable,
            when set, takes precedence over this flag.

    Example:
    ``` python

        from kedro.io import DataCatalog, MemoryDataset
        from kedro_datasets.pandas import CSVDataset

        # Define datasets
        datasets = {
            "cars": CSVDataset(filepath="cars.csv"),
            "planes": MemoryDataset(data={"type": "jet", "capacity": 200}),
        }

        # Initialize the catalog
        catalog = DataCatalog(
            datasets=datasets,
            load_versions={"cars": "2023-01-01T00.00.00"},
            save_version="2023-01-02T00.00.00",
        )

        print(catalog)
    ```
    """
    self._config_resolver = config_resolver or CatalogConfigResolver(
        default_runtime_patterns=self.default_runtime_patterns
    )
    self._datasets: dict[str, AbstractDataset] = datasets or {}
    self._lazy_datasets: dict[str, _LazyDataset] = {}
    self._load_versions, self._save_version = self._validate_versions(
        datasets, load_versions or {}, save_version
    )

    self.validation_enabled = validation_enabled
    self._validator_specs: dict[str, ValidatorSpec] = {}
    self._validators: dict[str, Any] = {}
    self._save_validated: set[str] = set()

    for ds_name in list(self._config_resolver.config):
        if ds_name in self._datasets:
            self._logger.warning(
                f"Cannot register dataset '{ds_name}' from config: a dataset with the same name "
                f"was already provided in the `datasets` argument."
            )
            self._config_resolver.config.pop(ds_name)
        else:
            self._add_from_config(ds_name, self._config_resolver.config[ds_name])

_config_resolver instance-attribute

_config_resolver = config_resolver or CatalogConfigResolver(default_runtime_patterns=self.default_runtime_patterns)

_datasets instance-attribute

_datasets = datasets or {}

_lazy_datasets instance-attribute

_lazy_datasets = {}

_logger property

_logger

_save_validated instance-attribute

_save_validated = set()

_validator_specs instance-attribute

_validator_specs = {}

_validators instance-attribute

_validators = {}

config_resolver property

config_resolver

Get the CatalogConfigResolver instance associated with this DataCatalog.

The CatalogConfigResolver is responsible for resolving dataset factory patterns and configurations dynamically.

Returns:

Example:

    catalog = DataCatalog(datasets={"example": MemoryDataset()})
    resolver = catalog.config_resolver
    print(resolver)

default_runtime_patterns class-attribute instance-attribute

default_runtime_patterns = {'{default}': {'type': 'kedro.io.MemoryDataset'}}

validation_enabled instance-attribute

validation_enabled = validation_enabled

validator_specs property

validator_specs

Parsed validator declarations, keyed by dataset name.

Returns:

  • dict[str, ValidatorSpec] –

    A copy of the mapping of dataset names to their parsed

  • dict[str, ValidatorSpec] –

    ValidatorSpec objects. Use validators for the serialised

  • dict[str, ValidatorSpec] –

    catalog-configuration form.

validators property

validators

Validator declarations captured from the catalog configuration.

Returns:

  • dict[str, Any] –

    A mapping of dataset names to their validator configuration in the

  • same shape it can be declared in the catalog –

    a plain class-path

  • dict[str, Any] –

    string for shorthand declarations or a dictionary for the long

  • dict[str, Any] –

    form.

__contains__

__contains__(dataset_name)

Check if a dataset is registered in the catalog or matches a dataset/user catch all pattern

Parameters:

  • dataset_name (str) –

    The name of the dataset to check.

Returns:

  • bool –

    True if the dataset is registered or matches a pattern, False otherwise.

Example:

    catalog = DataCatalog(datasets={"example": MemoryDataset()})
    "example" in catalog
    # True
    "nonexistent" in catalog
    # False

Source code in kedro/io/data_catalog.py
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
def __contains__(self, dataset_name: str) -> bool:
    """
    Check if a dataset is registered in the catalog
    or matches a dataset/user catch all pattern

    Args:
        dataset_name: The name of the dataset to check.

    Returns:
        True if the dataset is registered or matches a pattern, False otherwise.

    Example:
    ```python

        catalog = DataCatalog(datasets={"example": MemoryDataset()})
        "example" in catalog
        # True
        "nonexistent" in catalog
        # False
    ```
    """
    return (
        dataset_name in self._datasets
        or dataset_name in self._lazy_datasets
        or self._config_resolver.match_dataset_pattern(dataset_name) is not None
        or self._config_resolver.match_user_catch_all_pattern(dataset_name)
        is not None
    )

__eq__

__eq__(other)

Compare two catalogs based on materialized datasets, lazy datasets and all dataset factory patterns.

Parameters:

  • other (Any) –

    Another DataCatalog instance to compare.

Returns:

  • bool –

    True if the catalogs are equivalent, False otherwise.

Example:

    catalog1 = DataCatalog(datasets={"example": MemoryDataset()})
    catalog2 = DataCatalog(datasets={"example": MemoryDataset()})
    catalog1 == catalog2
    # False

Source code in kedro/io/data_catalog.py
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
def __eq__(
    self, other: Any
) -> bool:  # Any type to silence warning on mkdocs strict mode
    """
    Compare two catalogs based on materialized datasets, lazy datasets and all dataset factory patterns.

    Args:
        other: Another `DataCatalog` instance to compare.

    Returns:
        True if the catalogs are equivalent, False otherwise.

    Example:
    ```python
        catalog1 = DataCatalog(datasets={"example": MemoryDataset()})
        catalog2 = DataCatalog(datasets={"example": MemoryDataset()})
        catalog1 == catalog2
        # False
    ```
    """
    return (
        self._datasets,
        self._lazy_datasets,
        self._config_resolver.list_patterns(),
    ) == (
        other._datasets,
        other._lazy_datasets,
        other.config_resolver.list_patterns(),
    )

__getitem__

__getitem__(ds_name)

Get a dataset by name from the catalog.

If a dataset is not materialized but matches dataset_pattern or user_catch_all_pattern by default or runtime_patterns if fallback_to_runtime_pattern is enabled, it is instantiated and added to the catalog first, then returned.

Parameters:

  • ds_name (str) –

    The name of the dataset.

Returns:

Raises:

Example:

    catalog = DataCatalog(datasets={"example": MemoryDataset()})
    dataset = catalog["example"]
    print(dataset)
    # MemoryDataset()

Source code in kedro/io/data_catalog.py
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
def __getitem__(self, ds_name: str) -> AbstractDataset:
    """
    Get a dataset by name from the catalog.

    If a dataset is not materialized but matches dataset_pattern or user_catch_all_pattern
    by default or runtime_patterns if fallback_to_runtime_pattern is enabled,
    it is instantiated and added to the catalog first, then returned.

    Args:
        ds_name: The name of the dataset.

    Returns:
        The dataset instance.

    Raises:
        DatasetNotFoundError: If the dataset is not found.

    Example:
    ```python
        catalog = DataCatalog(datasets={"example": MemoryDataset()})
        dataset = catalog["example"]
        print(dataset)
        # MemoryDataset()
    ```
    """
    dataset = self.get(ds_name)
    if dataset is None:
        raise DatasetNotFoundError(f"Dataset '{ds_name}' not found in the catalog")
    return dataset

__getstate__

__getstate__()

Prepare the catalog state for pickling.

Resolved validator instances (_validators) may hold unpicklable objects (e.g. schema instances), so the cache is dropped and lazily rebuilt from _validator_specs in the target process. The _save_validated bookkeeping is per-process state and is reset.

Source code in kedro/io/data_catalog.py
422
423
424
425
426
427
428
429
430
431
432
433
def __getstate__(self) -> dict[str, Any]:
    """Prepare the catalog state for pickling.

    Resolved validator instances (`_validators`) may hold unpicklable
    objects (e.g. schema instances), so the cache is dropped and lazily
    rebuilt from `_validator_specs` in the target process. The
    `_save_validated` bookkeeping is per-process state and is reset.
    """
    state = self.__dict__.copy()
    state["_validators"] = {}
    state["_save_validated"] = set()
    return state

__iter__

__iter__()

Iterate over all dataset names in the catalog, including both materialized and lazy datasets.

Yields:

  • str –

    Dataset names.

Example:

    catalog = DataCatalog(datasets={"example": MemoryDataset()})
    for dataset_name in catalog:
        print(dataset_name)
    # example

Source code in kedro/io/data_catalog.py
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
def __iter__(self) -> Iterator[str]:
    """
    Iterate over all dataset names in the catalog, including both materialized and lazy datasets.

    Yields:
        Dataset names.

    Example:
    ```python
        catalog = DataCatalog(datasets={"example": MemoryDataset()})
        for dataset_name in catalog:
            print(dataset_name)
        # example
    ```
    """
    yield from self.keys()

__len__

__len__()

Get the number of datasets registered in the catalog, including both materialized and lazy datasets.

Returns:

  • int –

    The number of datasets.

Example:

    catalog = DataCatalog(datasets={"example": MemoryDataset()})
    len(catalog)
    # 1

Source code in kedro/io/data_catalog.py
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
def __len__(self) -> int:
    """
    Get the number of datasets registered in the catalog, including both materialized and lazy datasets.

    Returns:
        The number of datasets.

    Example:
    ```python
        catalog = DataCatalog(datasets={"example": MemoryDataset()})
        len(catalog)
        # 1
    ```
    """
    return len(self.keys())

__repr__

__repr__()

Return a string representation of the DataCatalog.

The representation includes both lazy and fully initialized datasets in the catalog.

Returns:

  • str –

    A string representation of the catalog.

Example:

    catalog = DataCatalog(datasets={"example": MemoryDataset()})
    print(repr(catalog))
    # "example: kedro.io.memory_dataset.MemoryDataset()"

Source code in kedro/io/data_catalog.py
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
def __repr__(self) -> str:
    """
    Return a string representation of the `DataCatalog`.

    The representation includes both lazy and fully initialized datasets
    in the catalog.

    Returns:
        A string representation of the catalog.

    Example:
    ```python

        catalog = DataCatalog(datasets={"example": MemoryDataset()})
        print(repr(catalog))
        # "example: kedro.io.memory_dataset.MemoryDataset()"
    ```
    """
    combined = self._lazy_datasets | self._datasets
    lines = []
    for key, dataset in combined.items():
        lines.append(f"'{key}': {dataset!r}")
    return "\n".join(lines)

__setitem__

__setitem__(key, value)

Registers a dataset or raw data into the catalog using the specified name.

If the name already exists, the dataset will be replaced and relevant internal mappings (lazy datasets, config, versions) will be cleared to avoid conflicts.

The value can either be raw data or a Kedro dataset (i.e., an instance of a class inheriting from AbstractDataset). If raw data is provided, it will be automatically wrapped in a MemoryDataset before being added to the catalog.

Parameters:

  • key (str) –

    Name of the dataset.

  • value (Any) –

    Either an instance of AbstractDataset, _LazyDataset, or raw data (e.g., DataFrame, list). If raw data is provided, it is automatically wrapped as a MemoryDataset.

Example:

    from kedro_datasets.pandas import CSVDataset
    import pandas as pd
    df = pd.DataFrame({"col1": [1, 2], "col2": [4, 5], "col3": [5, 6]})
    catalog = DataCatalog()
    catalog["data_df"] = df  # Add raw data as a MemoryDataset

    assert catalog.load("data_df").equals(df)

    csv_dataset = CSVDataset(filepath="test.csv")
    csv_dataset.save(df)
    catalog["data_csv_dataset"] = csv_dataset  # Add a dataset instance

    assert catalog.load("data_csv_dataset").equals(df)

Source code in kedro/io/data_catalog.py
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
def __setitem__(self, key: str, value: Any) -> None:
    """Registers a dataset or raw data into the catalog using the specified name.

    If the name already exists, the dataset will be replaced and relevant internal mappings
    (lazy datasets, config, versions) will be cleared to avoid conflicts.

    The value can either be raw data or a Kedro dataset (i.e., an instance of a class
    inheriting from ``AbstractDataset``). If raw data is provided, it will be automatically
    wrapped in a ``MemoryDataset`` before being added to the catalog.

    Args:
        key: Name of the dataset.
        value: Either an instance of `AbstractDataset`, `_LazyDataset`, or raw data (e.g., DataFrame, list).
            If raw data is provided, it is automatically wrapped as a `MemoryDataset`.

    Example:
    ```python

        from kedro_datasets.pandas import CSVDataset
        import pandas as pd
        df = pd.DataFrame({"col1": [1, 2], "col2": [4, 5], "col3": [5, 6]})
        catalog = DataCatalog()
        catalog["data_df"] = df  # Add raw data as a MemoryDataset

        assert catalog.load("data_df").equals(df)

        csv_dataset = CSVDataset(filepath="test.csv")
        csv_dataset.save(df)
        catalog["data_csv_dataset"] = csv_dataset  # Add a dataset instance

        assert catalog.load("data_csv_dataset").equals(df)
    ```
    """
    if key in self._datasets or key in self._lazy_datasets:
        self._logger.warning("Replacing dataset '%s'", key)
        self._datasets.pop(key, None)
        self._lazy_datasets.pop(key, None)
        self._config_resolver.config.pop(key, None)
        self._load_versions.pop(key, None)
        self._validator_specs.pop(key, None)
        self._validators.pop(key, None)
        self._save_validated.discard(key)
    if isinstance(value, AbstractDataset):
        self._load_versions, self._save_version = self._validate_versions(
            {key: value}, self._load_versions, self._save_version
        )
        self._datasets[key] = value
    elif isinstance(value, _LazyDataset):
        self._lazy_datasets[key] = value
    else:
        self._logger.debug(f"Adding input data {key} as a default MemoryDataset")
        self._datasets[key] = MemoryDataset(data=value)  # type: ignore[abstract]

__setstate__

__setstate__(state)

Restore the catalog state after unpickling with fresh per-process validator caches.

Source code in kedro/io/data_catalog.py
435
436
437
438
439
440
def __setstate__(self, state: dict[str, Any]) -> None:
    """Restore the catalog state after unpickling with fresh per-process
    validator caches."""
    self.__dict__.update(state)
    self._validators = {}
    self._save_validated = set()

_add_from_config

_add_from_config(ds_name, ds_config)

Create a _LazyDataset instance from the provided configuration and add it to the catalog.

This method validates the dataset configuration, creates a _LazyDataset instance, and registers it in the catalog. The _LazyDataset is a placeholder for a dataset that will be materialized only when accessed.

Parameters:

  • ds_name (str) –

    The name of the dataset to be added.

  • ds_config (dict[str, Any]) –

    The configuration dictionary for the dataset.

Raises:

  • DatasetError –

    If the provided dataset configuration is invalid (e.g., missing required keys like "type" or improperly formatted).

Example:

    catalog = DataCatalog()
    dataset_config = {"type": "pandas.CSVDataset", "filepath": "example.csv"}
    catalog._add_from_config("example_dataset", dataset_config)
    "example_dataset" in catalog
    # True

Source code in kedro/io/data_catalog.py
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
def _add_from_config(self, ds_name: str, ds_config: dict[str, Any]) -> None:
    """
    Create a `_LazyDataset` instance from the provided configuration and add it to the catalog.

    This method validates the dataset configuration, creates a `_LazyDataset` instance,
    and registers it in the catalog. The `_LazyDataset` is a placeholder for a dataset
    that will be materialized only when accessed.

    Args:
        ds_name: The name of the dataset to be added.
        ds_config: The configuration dictionary for the dataset.

    Raises:
        DatasetError: If the provided dataset configuration is invalid (e.g., missing
            required keys like "type" or improperly formatted).

    Example:
    ```python
        catalog = DataCatalog()
        dataset_config = {"type": "pandas.CSVDataset", "filepath": "example.csv"}
        catalog._add_from_config("example_dataset", dataset_config)
        "example_dataset" in catalog
        # True
    ```
    """
    validator_spec = None
    if isinstance(ds_config, dict) and VALIDATOR_KEY in ds_config:
        from kedro.validation.core import ValidatorSpec

        validator_spec = ValidatorSpec.from_dataset_config(
            ds_name, ds_config[VALIDATOR_KEY]
        )
        # Build a cleaned copy so the validator key never reaches the
        # dataset constructor. The original dict must not be mutated as it
        # may be the config resolver's own store.
        ds_config = {k: v for k, v in ds_config.items() if k != VALIDATOR_KEY}

    self._validate_dataset_config(ds_name, ds_config)
    ds = _LazyDataset(
        ds_name,
        ds_config,
        self._load_versions.get(ds_name),
        self._save_version,
    )

    self.__setitem__(ds_name, ds)

    # Assigned after __setitem__ so the replacement branch clearing stale
    # validator state cannot wipe the spec captured for this entry.
    if validator_spec is not None:
        self._validator_specs[ds_name] = validator_spec

_ipython_key_completions_

_ipython_key_completions_()
Source code in kedro/io/data_catalog.py
670
671
def _ipython_key_completions_(self) -> list[str]:
    return self.keys()

_is_validation_enabled

_is_validation_enabled()

Resolve whether dataset validation is currently enabled.

The KEDRO_DATASET_VALIDATION environment variable, when set to a recognised value, wins over the catalog-level validation_enabled flag. Recognised values are 0/false/off (disabled) and 1/true/on (enabled). Unset or unrecognised values fall back to self.validation_enabled.

The environment variable is read on every operation so that the kill switch applies to a live session without rebuilding the catalog.

Returns:

  • bool –

    True if validation should be applied, False otherwise.

Source code in kedro/io/data_catalog.py
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
def _is_validation_enabled(self) -> bool:
    """Resolve whether dataset validation is currently enabled.

    The `KEDRO_DATASET_VALIDATION` environment variable, when set to a
    recognised value, wins over the catalog-level `validation_enabled`
    flag. Recognised values are `0`/`false`/`off` (disabled) and
    `1`/`true`/`on` (enabled). Unset or unrecognised values fall
    back to `self.validation_enabled`.

    The environment variable is read on every operation so that the kill
    switch applies to a live session without rebuilding the catalog.

    Returns:
        True if validation should be applied, False otherwise.
    """
    env_value = os.environ.get("KEDRO_DATASET_VALIDATION")
    if env_value is not None:
        normalised = env_value.strip().lower()
        if normalised in ("0", "false", "off"):
            return False
        if normalised in ("1", "true", "on"):
            return True
    return self.validation_enabled

_validate

_validate(ds_name, data, mode)

Apply the dataset's declared validator to data if applicable.

This is the single validation funnel for catalog load and save operations. Callers gate on _is_validation_enabled first. It is a no-op when no validator is declared for the dataset, when the validator is disabled or not declared for mode, or when skip_load_after_save applies.

Parameters:

  • ds_name (str) –

    The name of the dataset being loaded or saved.

  • data (Any) –

    The data to validate.

  • mode (str) –

    Either "load" or "save".

Returns:

  • Any –

    The validated (possibly transformed/coerced) data, or data

  • Any –

    unchanged when validation does not apply or the validator's

  • Any –

    severity is "warn" and validation failed.

Raises:

  • DataValidationError –

    If validation fails and the validator's severity is "error".

  • ValidationConfigurationError –

    If the declared validator cannot be resolved.

Source code in kedro/io/data_catalog.py
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
def _validate(self, ds_name: str, data: Any, mode: str) -> Any:
    """Apply the dataset's declared validator to `data` if applicable.

    This is the single validation funnel for catalog `load` and `save`
    operations. Callers gate on `_is_validation_enabled` first. It is a
    no-op when no validator is declared for the dataset, when the
    validator is disabled or not declared for `mode`, or when
    `skip_load_after_save` applies.

    Args:
        ds_name: The name of the dataset being loaded or saved.
        data: The data to validate.
        mode: Either `"load"` or `"save"`.

    Returns:
        The validated (possibly transformed/coerced) data, or `data`
        unchanged when validation does not apply or the validator's
        severity is `"warn"` and validation failed.

    Raises:
        DataValidationError: If validation fails and the validator's
            severity is `"error"`.
        ValidationConfigurationError: If the declared validator cannot be
            resolved.
    """
    spec = self._validator_specs.get(ds_name)
    if spec is None or mode not in spec.on or not spec.enabled:
        return data

    if (
        mode == "load"
        and spec.skip_load_after_save
        and ds_name in self._save_validated
    ):
        return data

    from kedro.validation.core import resolve_validator
    from kedro.validation.exceptions import DataValidationError

    validator = self._validators.get(ds_name)
    if validator is None:
        # `setdefault` so that callers racing on the first use of a dataset
        # all end up with the same validator instance.
        validator = self._validators.setdefault(ds_name, resolve_validator(spec))

    try:
        validated = validator.validate(data)
    except DataValidationError as exc:
        exc.dataset_name = ds_name
        exc.mode = mode
        if exc.validator is None:
            exc.validator = spec.class_path
        if spec.severity == "warn":
            self._logger.warning(str(exc))
            return data
        raise
    except Exception as exc:
        wrapped = DataValidationError(
            str(exc),
            dataset_name=ds_name,
            mode=mode,
            validator=spec.class_path,
        )
        wrapped.__cause__ = exc
        if spec.severity == "warn":
            self._logger.warning(str(wrapped))
            return data
        raise wrapped from exc

    if mode == "save":
        self._save_validated.add(ds_name)

    return validated

_validate_dataset_config staticmethod

_validate_dataset_config(ds_name, ds_config)

Validate the configuration of a dataset in the catalog.

This method ensures that the dataset configuration is a dictionary and contains the required "type" key. If the configuration is invalid, it raises a DatasetError with a helpful error message.

Parameters:

  • ds_name (str) –

    The name of the dataset being validated.

  • ds_config (Any) –

    The configuration of the dataset to validate.

Raises:

  • DatasetError –

    If the dataset configuration is not a dictionary or if the "type" key is missing from the configuration.

Example:

    config = {
        "example_dataset": {
            "type": "pandas.CSVDataset",
            "filepath": "example.csv",
        }
    }
    DataCatalog._validate_dataset_config("example_dataset", config["example_dataset"])
    # No error raised

    invalid_config = {"example_dataset": {"filepath": "example.csv"}}
    DataCatalog._validate_dataset_config("example_dataset", invalid_config["example_dataset"])
    # Raises DatasetError: 'type' is missing from dataset catalog configuration.

Source code in kedro/io/data_catalog.py
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
@staticmethod
def _validate_dataset_config(ds_name: str, ds_config: Any) -> None:
    """
    Validate the configuration of a dataset in the catalog.

    This method ensures that the dataset configuration is a dictionary and contains
    the required "type" key. If the configuration is invalid, it raises a `DatasetError`
    with a helpful error message.

    Args:
        ds_name: The name of the dataset being validated.
        ds_config: The configuration of the dataset to validate.

    Raises:
        DatasetError: If the dataset configuration is not a dictionary or if the
            "type" key is missing from the configuration.

    Example:
    ```python
        config = {
            "example_dataset": {
                "type": "pandas.CSVDataset",
                "filepath": "example.csv",
            }
        }
        DataCatalog._validate_dataset_config("example_dataset", config["example_dataset"])
        # No error raised

        invalid_config = {"example_dataset": {"filepath": "example.csv"}}
        DataCatalog._validate_dataset_config("example_dataset", invalid_config["example_dataset"])
        # Raises DatasetError: 'type' is missing from dataset catalog configuration.
    ```
    """
    if not isinstance(ds_config, dict):
        raise DatasetError(
            f"Catalog entry '{ds_name}' is not a valid dataset configuration. "
            "\nHint: If this catalog entry is intended for variable interpolation, "
            "make sure that the key is preceded by an underscore."
        )

    if "type" not in ds_config:
        raise DatasetError(
            f"An exception occurred when parsing config for dataset '{ds_name}':\n"
            "'type' is missing from dataset catalog configuration."
            "\nHint: If this catalog entry is intended for variable interpolation, "
            "make sure that the top level key is preceded by an underscore."
        )

_validate_versions staticmethod

_validate_versions(datasets, load_versions, save_version)

Validates and synchronises dataset versions for loading and saving.

Ensures consistency of dataset versions across a catalog, particularly for versioned datasets. It updates load versions and validates that all save versions are consistent.

Parameters:

  • datasets (dict[str, AbstractDataset] | None) –

    A dictionary mapping dataset names to their instances. if None, no validation occurs.

  • load_versions (dict[str, str]) –

    A mapping between dataset names and versions to load.

  • save_version (str | None) –

    Version string to be used for save operations by all datasets with versioning enabled.

Returns:

  • tuple[dict[str, str], str | None] –

    Updated load_versions with load versions specified in the datasets and resolved save_version.

Raises:

  • VersionAlreadyExistsError –

    If a dataset's save version conflicts with the catalog's save version.

Source code in kedro/io/data_catalog.py
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
@staticmethod
def _validate_versions(
    datasets: dict[str, AbstractDataset] | None,
    load_versions: dict[str, str],
    save_version: str | None,
) -> tuple[dict[str, str], str | None]:
    """Validates and synchronises dataset versions for loading and saving.

    Ensures consistency of dataset versions across a catalog, particularly
    for versioned datasets. It updates load versions and validates that all
    save versions are consistent.

    Args:
        datasets: A dictionary mapping dataset names to their instances.
            if None, no validation occurs.
        load_versions: A mapping between dataset names and versions
            to load.
        save_version: Version string to be used for ``save`` operations
            by all datasets with versioning enabled.

    Returns:
        Updated ``load_versions`` with load versions specified in the ``datasets``
            and resolved ``save_version``.

    Raises:
        VersionAlreadyExistsError: If a dataset's save version conflicts with
            the catalog's save version.
    """
    if not datasets:
        return load_versions, save_version

    cur_load_versions = load_versions.copy()
    cur_save_version = save_version

    for ds_name, ds in datasets.items():
        cur_ds = ds._dataset if isinstance(ds, CachedDataset) else ds

        if isinstance(cur_ds, AbstractVersionedDataset) and cur_ds._version:
            if cur_ds._version.load:
                cur_load_versions[ds_name] = cur_ds._version.load
            if cur_ds._version.save:
                cur_save_version = cur_save_version or cur_ds._version.save
                if cur_save_version != cur_ds._version.save:
                    raise VersionAlreadyExistsError(
                        f"Cannot add a dataset `{ds_name}` with `{cur_ds._version.save}` save version. "
                        f"Save version set for the catalog is `{cur_save_version}`"
                        f"All datasets in the catalog must have the same save version."
                    )

    return cur_load_versions, cur_save_version

confirm

confirm(ds_name)

Confirm a dataset by its name. Args: ds_name: Name of the dataset. Raises: DatasetNotFoundError: When a dataset with the given name has not yet been registered DatasetError: When the dataset does not have confirm method.

Source code in kedro/io/data_catalog.py
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
def confirm(self, ds_name: str) -> None:
    """Confirm a dataset by its name.
    Args:
        ds_name: Name of the dataset.
    Raises:
        DatasetNotFoundError: When a dataset with the given name
            has not yet been registered
        DatasetError: When the dataset does not have `confirm` method.
    """
    self._logger.info("Confirming dataset '%s'", ds_name)

    dataset = self[ds_name]

    if hasattr(dataset, "confirm"):
        dataset.confirm()
    else:
        raise DatasetError(f"Dataset '{ds_name}' does not have 'confirm' method")

exists

exists(ds_name)

Checks whether registered dataset exists by calling its exists() method. Raises a warning and returns False if exists() is not implemented.

Parameters:

  • ds_name (str) –

    A dataset to be checked.

Returns:

  • bool –

    Whether the dataset and its output exist.

Example:

    catalog = DataCatalog(datasets={"example": MemoryDataset(data=[1, 2, 3])})
    catalog.exists("example")
    True

Source code in kedro/io/data_catalog.py
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
def exists(self, ds_name: str) -> bool:
    """Checks whether registered dataset exists by calling its `exists()`
    method. Raises a warning and returns False if `exists()` is not
    implemented.

    Args:
        ds_name: A dataset to be checked.

    Returns:
        Whether the dataset and its output exist.

    Example:
    ```python
        catalog = DataCatalog(datasets={"example": MemoryDataset(data=[1, 2, 3])})
        catalog.exists("example")
        True
    ```
    """
    dataset = self.get(ds_name)
    return dataset.exists() if dataset else False

filter

filter(name_regex=None, type_regex=None, by_type=None)

Filter dataset names registered in the catalog based on name and/or type.

This method allows filtering datasets by their names and/or types. Regular expressions should be precompiled before passing them to name_regex or type_regex, but plain strings are also supported.

Parameters:

  • name_regex (Pattern[str] | str | None, default: None ) –

    Optional compiled regex pattern or string to filter dataset names.

  • type_regex (Pattern[str] | str | None, default: None ) –

    Optional compiled regex pattern or string to filter dataset types. The provided regex is matched against the full dataset type path, for example: kedro_datasets.pandas.parquet_dataset.ParquetDataset.

  • by_type (type | list[type] | None, default: None ) –

    Optional dataset type(s) to filter by. This performs an instance type check rather than a regex match. It can be a single dataset type or a list of types.

Returns:

  • List[str] –

    A list of dataset names that match the filtering criteria.

Example:

    import re
    catalog = DataCatalog()
    # get datasets where the substring 'raw' is present
    raw_data = catalog.filter(name_regex='raw')
    # get datasets where names start with 'model_' (precompiled regex)
    model_datasets = catalog.filter(name_regex=re.compile('^model_'))
    # get datasets of a specific type using type_regex
    csv_datasets = catalog.filter(type_regex='pandas.excel_dataset.ExcelDataset')
    # get datasets where names contain 'train' and type matches 'CSV' in the path
    catalog.filter(name_regex="train", type_regex="CSV")
    # get datasets where names include 'data' and are of a specific type
    from kedro_datasets.pandas import SQLQueryDataset
    catalog.filter(name_regex="data", by_type=SQLQueryDataset)
    # get datasets where names include 'data' and are of multiple specific types
    from kedro.io import MemoryDataset
    catalog.filter(name_regex="data", by_type=[MemoryDataset, SQLQueryDataset])

Source code in kedro/io/data_catalog.py
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
def filter(
    self,
    name_regex: re.Pattern[str] | str | None = None,
    type_regex: re.Pattern[str] | str | None = None,
    by_type: type | list[type] | None = None,
) -> List[str]:  # noqa: UP006
    """Filter dataset names registered in the catalog based on name and/or type.

    This method allows filtering datasets by their names and/or types. Regular expressions
    should be precompiled before passing them to `name_regex` or `type_regex`, but plain
    strings are also supported.

    Args:
        name_regex: Optional compiled regex pattern or string to filter dataset names.
        type_regex: Optional compiled regex pattern or string to filter dataset types.
            The provided regex is matched against the full dataset type path, for example:
            `kedro_datasets.pandas.parquet_dataset.ParquetDataset`.
        by_type: Optional dataset type(s) to filter by. This performs an instance type check
            rather than a regex match. It can be a single dataset type or a list of types.

    Returns:
        A list of dataset names that match the filtering criteria.

    Example:
    ```python
        import re
        catalog = DataCatalog()
        # get datasets where the substring 'raw' is present
        raw_data = catalog.filter(name_regex='raw')
        # get datasets where names start with 'model_' (precompiled regex)
        model_datasets = catalog.filter(name_regex=re.compile('^model_'))
        # get datasets of a specific type using type_regex
        csv_datasets = catalog.filter(type_regex='pandas.excel_dataset.ExcelDataset')
        # get datasets where names contain 'train' and type matches 'CSV' in the path
        catalog.filter(name_regex="train", type_regex="CSV")
        # get datasets where names include 'data' and are of a specific type
        from kedro_datasets.pandas import SQLQueryDataset
        catalog.filter(name_regex="data", by_type=SQLQueryDataset)
        # get datasets where names include 'data' and are of multiple specific types
        from kedro.io import MemoryDataset
        catalog.filter(name_regex="data", by_type=[MemoryDataset, SQLQueryDataset])
    ```

    """
    filtered = self.keys()

    # Apply name filter if specified
    if name_regex:
        filtered = [
            ds_name for ds_name in filtered if re.search(name_regex, ds_name)
        ]

    # Apply type filters if specified
    by_type_set = set()
    if by_type:
        if not isinstance(by_type, list):
            by_type = [by_type]
        for _type in by_type:
            by_type_set.add(f"{_type.__module__}.{_type.__qualname__}")

    if by_type_set or type_regex:
        filtered_types = []
        for ds_name in filtered:
            # Retrieve the dataset type
            str_type = self.get_type(ds_name) or ""
            # Match against type_regex and apply by_type filtering
            if (not type_regex or re.search(type_regex, str_type)) and (
                not by_type_set or str_type in by_type_set
            ):
                filtered_types.append(ds_name)

        return filtered_types

    return filtered

from_config classmethod

from_config(catalog, credentials=None, load_versions=None, save_version=None, validation_enabled=True)

Create a DataCatalog instance from configuration. This is a factory method used to provide developers with a way to instantiate DataCatalog with configuration parsed from configuration files.

Parameters:

  • catalog (dict[str, dict[str, Any]] | None) –

    A dictionary whose keys are the dataset names and the values are dictionaries with the constructor arguments for classes implementing AbstractDataset. The dataset class to be loaded is specified with the key type and their fully qualified class name. All kedro.io dataset can be specified by their class name only, i.e. their module name can be omitted.

  • credentials (dict[str, dict[str, Any]] | None, default: None ) –

    A dictionary containing credentials for different datasets. Use the credentials key in a AbstractDataset to refer to the appropriate credentials as shown in the example below.

  • load_versions (dict[str, str] | None, default: None ) –

    A mapping between dataset names and versions to load. Has no effect on datasets without enabled versioning.

  • save_version (str | None, default: None ) –

    Version string to be used for save operations by all datasets with enabled versioning. It must: a) be a case-insensitive string that conforms with operating system filename limitations, b) always return the latest version when sorted in lexicographical order.

  • validation_enabled (bool, default: True ) –

    Whether declared dataset validators are applied on load and save. Defaults to True.

Returns:

  • DataCatalog –

    An instantiated DataCatalog containing all specified

  • DataCatalog –

    datasets, created and ready to use.

Raises:

  • DatasetNotFoundError –

    When load_versions refers to a dataset that doesn't exist in the catalog.

Example:

    config = {
        "cars": {
            "type": "pandas.CSVDataset",
            "filepath": "cars.csv",
            "save_args": {"index": False}
        },
        "boats": {
            "type": "pandas.CSVDataset",
            "filepath": "s3://aws-bucket-name/boats.csv",
            "credentials": "boats_credentials",
            "save_args": {"index": False}
        }
    }
    credentials = {
        "boats_credentials": {
            "client_kwargs": {
                "aws_access_key_id": "<your key id>",
                "aws_secret_access_key": "<your secret>"
            }
        }
    }

    catalog = DataCatalog.from_config(config, credentials)
    df = catalog.load("cars")

    catalog.save("boats", df)

Source code in kedro/io/data_catalog.py
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
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
@classmethod
def from_config(
    cls,
    catalog: dict[str, dict[str, Any]] | None,
    credentials: dict[str, dict[str, Any]] | None = None,
    load_versions: dict[str, str] | None = None,
    save_version: str | None = None,
    validation_enabled: bool = True,
) -> DataCatalog:
    """Create a ``DataCatalog`` instance from configuration. This is a
    factory method used to provide developers with a way to instantiate
    ``DataCatalog`` with configuration parsed from configuration files.

    Args:
        catalog: A dictionary whose keys are the dataset names and
            the values are dictionaries with the constructor arguments
            for classes implementing ``AbstractDataset``. The dataset
            class to be loaded is specified with the key ``type`` and their
            fully qualified class name. All ``kedro.io`` dataset can be
            specified by their class name only, i.e. their module name
            can be omitted.
        credentials: A dictionary containing credentials for different
            datasets. Use the ``credentials`` key in a ``AbstractDataset``
            to refer to the appropriate credentials as shown in the example
            below.
        load_versions: A mapping between dataset names and versions
            to load. Has no effect on datasets without enabled versioning.
        save_version: Version string to be used for ``save`` operations
            by all datasets with enabled versioning. It must: a) be a
            case-insensitive string that conforms with operating system
            filename limitations, b) always return the latest version when
            sorted in lexicographical order.
        validation_enabled: Whether declared dataset validators are
            applied on `load` and `save`. Defaults to True.

    Returns:
        An instantiated ``DataCatalog`` containing all specified
        datasets, created and ready to use.

    Raises:
        DatasetNotFoundError: When `load_versions` refers to a dataset that doesn't
            exist in the catalog.

    Example:
    ```python
        config = {
            "cars": {
                "type": "pandas.CSVDataset",
                "filepath": "cars.csv",
                "save_args": {"index": False}
            },
            "boats": {
                "type": "pandas.CSVDataset",
                "filepath": "s3://aws-bucket-name/boats.csv",
                "credentials": "boats_credentials",
                "save_args": {"index": False}
            }
        }
        credentials = {
            "boats_credentials": {
                "client_kwargs": {
                    "aws_access_key_id": "<your key id>",
                    "aws_secret_access_key": "<your secret>"
                }
            }
        }

        catalog = DataCatalog.from_config(config, credentials)
        df = catalog.load("cars")

        catalog.save("boats", df)
    ```
    """
    catalog = catalog or {}
    config_resolver = CatalogConfigResolver(
        catalog, credentials, cls.default_runtime_patterns
    )
    save_version = save_version or generate_timestamp()
    load_versions = load_versions or {}

    missing_keys = [
        ds_name
        for ds_name in load_versions
        if not (
            ds_name in config_resolver.config
            or config_resolver.match_dataset_pattern(ds_name)
        )
    ]
    if missing_keys:
        raise DatasetNotFoundError(
            f"'load_versions' keys [{', '.join(sorted(missing_keys))}] "
            f"are not found in the catalog."
        )

    return cls(
        load_versions=load_versions,
        save_version=save_version,
        config_resolver=config_resolver,
        validation_enabled=validation_enabled,
    )

get

get(key, fallback_to_runtime_pattern=False, version=None)

Get a dataset by name from an internal collection of datasets.

If a dataset is not materialized but matches dataset_pattern or user_catch_all_pattern by default or runtime_patterns if fallback_to_runtime_pattern is enabled it is instantiated and added to the catalog first, then returned.

Parameters:

  • key (str) –

    A dataset name.

  • fallback_to_runtime_pattern (bool, default: False ) –

    Whether to use runtime_pattern to resolve dataset.

  • version (Version | None, default: None ) –

    Optional argument to get a specific version of the dataset.

Returns:

  • AbstractDataset | None –

    The dataset instance if found, otherwise None.

Example:

    catalog = DataCatalog(datasets={"example": MemoryDataset()})
    dataset = catalog.get("example")
    print(dataset)
    # MemoryDataset()

    missing = catalog.get("nonexistent")
    print(missing)
    # None

Source code in kedro/io/data_catalog.py
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
def get(
    self,
    key: str,
    fallback_to_runtime_pattern: bool = False,
    version: Version | None = None,
) -> AbstractDataset | None:
    """Get a dataset by name from an internal collection of datasets.

    If a dataset is not materialized but matches dataset_pattern or user_catch_all_pattern
    by default or runtime_patterns if fallback_to_runtime_pattern is enabled
    it is instantiated and added to the catalog first, then returned.

    Args:
        key: A dataset name.
        fallback_to_runtime_pattern: Whether to use runtime_pattern to resolve dataset.
        version: Optional argument to get a specific version of the dataset.

    Returns:
        The dataset instance if found, otherwise None.

    Example:
    ```python
        catalog = DataCatalog(datasets={"example": MemoryDataset()})
        dataset = catalog.get("example")
        print(dataset)
        # MemoryDataset()

        missing = catalog.get("nonexistent")
        print(missing)
        # None
    ```
    """
    if key not in self and not fallback_to_runtime_pattern:
        return None

    if not (key in self._datasets or key in self._lazy_datasets):
        ds_config = self._config_resolver.resolve_pattern(key)
        if ds_config:
            self._add_from_config(key, ds_config)

    lazy_dataset = self._lazy_datasets.pop(key, None)
    if lazy_dataset:
        self[key] = lazy_dataset.materialize()

    dataset = self._datasets[key]

    if version and isinstance(dataset, AbstractVersionedDataset):
        # we only want to return a similar-looking dataset,
        # not modify the one stored in the current catalog
        dataset = dataset._copy(_version=version)

    return dataset

get_type

get_type(ds_name)

Access dataset type without adding resolved dataset to the catalog.

Parameters:

  • ds_name (str) –

    The name of the dataset whose type is to be retrieved.

Returns:

  • str | None –

    The fully qualified type of the dataset (e.g., kedro.io.memory_dataset.MemoryDataset)

  • str | None –

    or None if dataset does not match dataset_patterns or user_catch_all_pattern.

Example:

    from kedro.io import DataCatalog, MemoryDataset
    catalog = DataCatalog(datasets={"example": MemoryDataset()})
    dataset_type = catalog.get_type("example")
    print(dataset_type)
    # kedro.io.memory_dataset.MemoryDataset

    missing_type = catalog.get_type("nonexistent")
    print(missing_type)
    # None

Source code in kedro/io/data_catalog.py
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
def get_type(self, ds_name: str) -> str | None:
    """
    Access dataset type without adding resolved dataset to the catalog.

    Args:
        ds_name: The name of the dataset whose type is to be retrieved.

    Returns:
        The fully qualified type of the dataset (e.g., `kedro.io.memory_dataset.MemoryDataset`)
        or None if dataset does not match dataset_patterns or user_catch_all_pattern.

    Example:
    ```python
        from kedro.io import DataCatalog, MemoryDataset
        catalog = DataCatalog(datasets={"example": MemoryDataset()})
        dataset_type = catalog.get_type("example")
        print(dataset_type)
        # kedro.io.memory_dataset.MemoryDataset

        missing_type = catalog.get_type("nonexistent")
        print(missing_type)
        # None
    ```
    """
    if ds_name not in self:
        return None

    if ds_name not in self._datasets and ds_name not in self._lazy_datasets:
        ds_config = self._config_resolver.resolve_pattern(ds_name)
        return str(_LazyDataset(ds_name, ds_config))

    if ds_name in self._lazy_datasets:
        return str(self._lazy_datasets[ds_name])

    class_type = type(self._datasets[ds_name])
    return f"{class_type.__module__}.{class_type.__qualname__}"

items

items()

Retrieve all dataset names and their corresponding dataset instances.

This method returns a list of tuples, where each tuple contains a dataset name and its corresponding dataset instance.

Returns:

  • List[tuple[str, AbstractDataset]] –

    A list of tuples containing dataset names and their corresponding dataset instances.

Example:

    from kedro.io import DataCatalog, MemoryDataset
    catalog = DataCatalog(datasets={"example": MemoryDataset()})
    dataset_items = catalog.items()
    print(dataset_items)
    # [('example', kedro.io.memory_dataset.MemoryDataset())]

Source code in kedro/io/data_catalog.py
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
def items(self) -> List[tuple[str, AbstractDataset]]:  # noqa: UP006
    """
    Retrieve all dataset names and their corresponding dataset instances.

    This method returns a list of tuples, where each tuple contains a dataset
    name and its corresponding dataset instance.

    Returns:
        A list of tuples containing dataset names and their corresponding dataset instances.

    Example:
    ```python

        from kedro.io import DataCatalog, MemoryDataset
        catalog = DataCatalog(datasets={"example": MemoryDataset()})
        dataset_items = catalog.items()
        print(dataset_items)
        # [('example', kedro.io.memory_dataset.MemoryDataset())]
    ```
    """
    return [(key, self[key]) for key in self]

keys

keys()

List all dataset names registered in the catalog, including both materialized and lazy datasets.

Returns:

  • List[str] –

    A list of all dataset names.

Example:

    catalog = DataCatalog(datasets={"example": MemoryDataset()})
    catalog.keys()
    # ['example']

Source code in kedro/io/data_catalog.py
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
def keys(self) -> List[str]:  # noqa: UP006
    """
    List all dataset names registered in the catalog, including both materialized and lazy datasets.

    Returns:
        A list of all dataset names.

    Example:
    ```python
        catalog = DataCatalog(datasets={"example": MemoryDataset()})
        catalog.keys()
        # ['example']
    ```
    """
    return list(self._lazy_datasets.keys()) + list(self._datasets.keys())

load

load(ds_name, version=None)

Loads a registered dataset.

Parameters:

  • ds_name (str) –

    The name of the dataset to be loaded.

  • version (str | None, default: None ) –

    Optional argument for concrete data version to be loaded. Works only with versioned datasets.

Returns:

  • Any –

    The loaded data as configured.

Raises:

Example:

    from kedro.io import DataCatalog
    from kedro_datasets.pandas import CSVDataset
    cars = CSVDataset(filepath="cars.csv", load_args=None, save_args={"index": False})
    catalog = DataCatalog(datasets={'cars': cars})
    df = catalog.load("cars")

Source code in kedro/io/data_catalog.py
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
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
def load(self, ds_name: str, version: str | None = None) -> Any:
    """Loads a registered dataset.

    Args:
        ds_name: The name of the dataset to be loaded.
        version: Optional argument for concrete data version to be loaded.
            Works only with versioned datasets.

    Returns:
        The loaded data as configured.

    Raises:
        DatasetNotFoundError: When a dataset with the given name
            has not yet been registered.
        DatasetError: When an error occurs during loading the dataset.

    Example:
    ```python
        from kedro.io import DataCatalog
        from kedro_datasets.pandas import CSVDataset
        cars = CSVDataset(filepath="cars.csv", load_args=None, save_args={"index": False})
        catalog = DataCatalog(datasets={'cars': cars})
        df = catalog.load("cars")
    ```
    """
    load_version = Version(version, None) if version else None
    dataset = self.get(ds_name, version=load_version)

    if dataset is None:
        error_msg = f"Dataset '{ds_name}' not found in the catalog"
        raise DatasetNotFoundError(error_msg)

    self._logger.info(
        "Loading data from %s (%s)...",
        ds_name,
        type(dataset).__name__,
        extra={"rich_format": ["dark_orange"]},
    )

    try:
        data = dataset.load()
    except DatasetError as e:
        raise DatasetError(f"{ds_name}: {e}") from e
    if self._is_validation_enabled():
        data = self._validate(ds_name, data, mode="load")
    return data

release

release(ds_name)

Release any cached data associated with a dataset Args: ds_name: A dataset to be checked. Raises: DatasetNotFoundError: When a dataset with the given name has not yet been registered.

Example:

    catalog = DataCatalog(datasets={"example": MemoryDataset(data=[1, 2, 3])})
    catalog.release("example")

Source code in kedro/io/data_catalog.py
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
def release(self, ds_name: str) -> None:
    """Release any cached data associated with a dataset
    Args:
        ds_name: A dataset to be checked.
    Raises:
        DatasetNotFoundError: When a dataset with the given name
            has not yet been registered.

    Example:
    ```python
        catalog = DataCatalog(datasets={"example": MemoryDataset(data=[1, 2, 3])})
        catalog.release("example")
    ```
    """
    dataset = self[ds_name]

    dataset.release()
    self._save_validated.discard(ds_name)

save

save(ds_name, data)

Save data to a registered dataset.

Parameters:

  • ds_name (str) –

    The name of the dataset to be saved.

  • data (Any) –

    A data object to be saved as configured in the registered dataset.

Raises:

Example:

    import pandas as pd

    from kedro.io import DataCatalog
    from kedro_datasets.pandas import CSVDataset

    cars = CSVDataset(filepath="cars.csv", load_args=None, save_args={"index": False})
    catalog = DataCatalog(datasets={'cars': cars})
    df = pd.DataFrame({'col1': [1, 2], 'col2': [4, 5], 'col3': [5, 6]})
    catalog.save("cars", df)

Source code in kedro/io/data_catalog.py
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
def save(self, ds_name: str, data: Any) -> None:
    """Save data to a registered dataset.

    Args:
        ds_name: The name of the dataset to be saved.
        data: A data object to be saved as configured in the registered
            dataset.

    Raises:
        DatasetNotFoundError: When a dataset with the given name
            has not yet been registered.
        DatasetError: When an error occurs during saving the dataset.

    Example:
    ```python
        import pandas as pd

        from kedro.io import DataCatalog
        from kedro_datasets.pandas import CSVDataset

        cars = CSVDataset(filepath="cars.csv", load_args=None, save_args={"index": False})
        catalog = DataCatalog(datasets={'cars': cars})
        df = pd.DataFrame({'col1': [1, 2], 'col2': [4, 5], 'col3': [5, 6]})
        catalog.save("cars", df)
    ```
    """
    dataset = self[ds_name]

    self._logger.info(
        "Saving data to %s (%s)...",
        ds_name,
        type(dataset).__name__,
        extra={"rich_format": ["dark_orange"]},
    )

    if self._is_validation_enabled():
        data = self._validate(ds_name, data, mode="save")
    try:
        dataset.save(data)
    except DatasetError as e:
        # The validated data never reached storage, so the on-disk state
        # is unknown; the next load must validate again.
        self._save_validated.discard(ds_name)
        raise DatasetError(f"{ds_name}: {e}") from e
    except BaseException:
        # Custom datasets are free to raise anything, and even an
        # interrupt must not leave the dataset marked as save-validated.
        self._save_validated.discard(ds_name)
        raise

to_config

to_config()

Converts the DataCatalog instance into a configuration format suitable for serialization. This includes datasets, credentials, and versioning information.

This method is only applicable to catalogs that contain datasets initialized with static, primitive parameters. For example, it will work fine if one passes credentials as dictionary to GBQQueryDataset but not as google.auth.credentials.Credentials object. See https://github.com/kedro-org/kedro-plugins/issues/950 for the details.

Returns:

  • A tuple containing –

    catalog: A dictionary mapping dataset names to their unresolved configurations, excluding in-memory datasets.

    credentials: A dictionary of unresolved credentials extracted from dataset configurations.

    load_versions: A dictionary mapping dataset names to specific versions to be loaded, or None if no version is set.

    save_version: A global version identifier for saving datasets, or None if not specified.

Example:

    from kedro.io import DataCatalog
    from kedro_datasets.pandas import CSVDataset

    cars = CSVDataset(
        filepath="cars.csv",
        load_args=None,
        save_args={"index": False}
    )
    catalog = DataCatalog(datasets={'cars': cars})

    config, credentials, load_versions, save_version = catalog.to_config()

    new_catalog = DataCatalog.from_config(config, credentials, load_versions, save_version)

Source code in kedro/io/data_catalog.py
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
def to_config(
    self,
) -> tuple[
    dict[str, dict[str, Any]],
    dict[str, dict[str, Any]],
    dict[str, str | None],
    str | None,
]:
    """Converts the `DataCatalog` instance into a configuration format suitable for
    serialization. This includes datasets, credentials, and versioning information.

    This method is only applicable to catalogs that contain datasets initialized with static, primitive
    parameters. For example, it will work fine if one passes credentials as dictionary to
    `GBQQueryDataset` but not as `google.auth.credentials.Credentials` object. See
    https://github.com/kedro-org/kedro-plugins/issues/950 for the details.

    Returns:
        A tuple containing:
            catalog: A dictionary mapping dataset names to their unresolved configurations,
                excluding in-memory datasets.

            credentials: A dictionary of unresolved credentials extracted from dataset configurations.

            load_versions: A dictionary mapping dataset names to specific versions to be loaded,
                or `None` if no version is set.

            save_version: A global version identifier for saving datasets, or `None` if not specified.

    Example:
    ```python
        from kedro.io import DataCatalog
        from kedro_datasets.pandas import CSVDataset

        cars = CSVDataset(
            filepath="cars.csv",
            load_args=None,
            save_args={"index": False}
        )
        catalog = DataCatalog(datasets={'cars': cars})

        config, credentials, load_versions, save_version = catalog.to_config()

        new_catalog = DataCatalog.from_config(config, credentials, load_versions, save_version)
    ```
    """
    catalog: dict[str, dict[str, Any]] = {}
    credentials: dict[str, dict[str, Any]] = {}
    load_versions: dict[str, str | None] = {}

    for ds_name, ds in self._lazy_datasets.items():
        if _is_memory_dataset(ds.config.get(TYPE_KEY, "")):
            continue
        unresolved_config, unresolved_credentials = (
            self._config_resolver._unresolve_credentials(ds_name, ds.config)
        )
        catalog[ds_name] = unresolved_config
        credentials.update(unresolved_credentials)
        load_versions[ds_name] = self._load_versions.get(ds_name, None)

    for ds_name, ds in self._datasets.items():  # type: ignore[assignment]
        if _is_memory_dataset(ds):  # type: ignore[arg-type]
            continue
        resolved_config = ds._init_config()  # type: ignore[attr-defined]
        unresolved_config, unresolved_credentials = (
            self._config_resolver._unresolve_credentials(ds_name, resolved_config)
        )
        catalog[ds_name] = unresolved_config
        credentials.update(unresolved_credentials)
        load_versions[ds_name] = self._load_versions.get(ds_name, None)

    # Re-inject validator declarations: the validator key is stripped from
    # dataset configs before they reach _LazyDataset or the dataset
    # constructor, so it must be restored here for round-tripping.
    for ds_name, spec in self._validator_specs.items():
        if ds_name in catalog:
            catalog[ds_name][VALIDATOR_KEY] = spec.to_config()

    return catalog, credentials, load_versions, self._save_version

values

values()

Retrieve all datasets registered in the catalog.

This method returns a list of all dataset instances currently registered in the catalog, including both materialized and lazy datasets.

Returns:

Example:

    from kedro.io import DataCatalog, MemoryDataset
    catalog = DataCatalog(datasets={"example": MemoryDataset()})
    dataset_values = catalog.values()
    print(dataset_values)
    # [kedro.io.memory_dataset.MemoryDataset()]

Source code in kedro/io/data_catalog.py
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
def values(self) -> List[AbstractDataset]:  # noqa: UP006
    """
    Retrieve all datasets registered in the catalog.

    This method returns a list of all dataset instances currently registered
    in the catalog, including both materialized and lazy datasets.

    Returns:
        A list of dataset instances.

    Example:
    ```python
        from kedro.io import DataCatalog, MemoryDataset
        catalog = DataCatalog(datasets={"example": MemoryDataset()})
        dataset_values = catalog.values()
        print(dataset_values)
        # [kedro.io.memory_dataset.MemoryDataset()]
    ```
    """
    return [self[key] for key in self]