kedro.context.KedroContext

class kedro.context.KedroContext(project_path, env=None)[source]

Bases: abc.ABC

KedroContext is the base class which holds the configuration and Kedro’s main functionality. Project-specific context class should extend this abstract class and implement the all abstract methods.

CONF_ROOT

Name of root directory containing project configuration.

Default name is "conf".

Example:

from kedro.context import KedroContext
from kedro.pipeline import Pipeline

class ProjectContext(KedroContext):
    @property
    def pipeline(self) -> Pipeline:
        return Pipeline([])

Attributes

KedroContext.CONF_ROOT
KedroContext.catalog Read-only property referring to Kedro’s DataCatalog for this context.
KedroContext.config_loader Read-only property referring to Kedro’s ConfigLoader for this context.
KedroContext.io Read-only alias property referring to Kedro’s DataCatalog for this context.
KedroContext.pipeline Abstract property for Pipeline getter.
KedroContext.project_name Abstract property for Kedro project name.
KedroContext.project_path Read-only property containing Kedro’s root project directory.
KedroContext.project_version Abstract property for Kedro version.

Methods

KedroContext.__init__(project_path[, env]) Create a context object by providing the root of a Kedro project and the environment configuration subfolders (see kedro.config.ConfigLoader)
KedroContext.run([tags, runner, node_names, …]) Runs the pipeline with a specified runner.
CONF_ROOT = 'conf'
__init__(project_path, env=None)[source]

Create a context object by providing the root of a Kedro project and the environment configuration subfolders (see kedro.config.ConfigLoader)

Raises:

KedroContextError – If there is a mismatch between Kedro project version and package version.

Parameters:
  • project_path (Union[Path, str]) – Project path to define the context for.
  • env (Optional[str]) – Optional argument for configuration default environment to be used
  • running the pipeline. If not specified, it defaults to "local". (for) –
catalog

Read-only property referring to Kedro’s DataCatalog for this context.

Return type:DataCatalog
Returns:DataCatalog defined in catalog.yml.
config_loader

Read-only property referring to Kedro’s ConfigLoader for this context.

Return type:ConfigLoader
Returns:Instance of ConfigLoader created by _create_config_loader().
io

Read-only alias property referring to Kedro’s DataCatalog for this context.

Return type:DataCatalog
Returns:DataCatalog defined in catalog.yml.
pipeline

Abstract property for Pipeline getter.

Return type:Pipeline
Returns:Defined pipeline.
project_name

Abstract property for Kedro project name.

Return type:str
Returns:Name of Kedro project.
project_path

Read-only property containing Kedro’s root project directory.

Return type:Path
Returns:Project directory.
project_version

Abstract property for Kedro version.

Return type:str
Returns:Kedro version.
run(tags=None, runner=None, node_names=None, from_nodes=None, to_nodes=None, pipeline=None, catalog=None)[source]

Runs the pipeline with a specified runner.

Parameters:
  • tags (Optional[Iterable[str]]) – An optional list of node tags which should be used to filter the nodes of the Pipeline. If specified, only the nodes containing any of these tags will be run.
  • runner (Optional[AbstractRunner]) – An optional parameter specifying the runner that you want to run the pipeline with.
  • node_names (Optional[Iterable[str]]) – An optional list of node names which should be used to filter the nodes of the Pipeline. If specified, only the nodes with these names will be run.
  • from_nodes (Optional[Iterable[str]]) – An optional list of node names which should be used as a starting point of the new Pipeline.
  • to_nodes (Optional[Iterable[str]]) – An optional list of node names which should be used as an end point of the new Pipeline.
  • pipeline (Optional[Pipeline]) – Optional Pipeline to run, defaults to self.pipeline.
  • catalog (Optional[DataCatalog]) – Optional DataCatalog to run with, defaults to self.catalog.
Raises:

KedroContextError – If the resulting Pipeline is empty or incorrect tags are provided.

Return type:

Dict[str, Any]

Returns:

Any node outputs that cannot be processed by the DataCatalog. These are returned in a dictionary, where the keys are defined by the node outputs.