kedro.framework.context.KedroContext¶
-
class
kedro.framework.context.
KedroContext
(project_path, env=None, extra_params=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".
-
hooks
¶ The list of hooks provided by user to extend KedroContext’s execution.
Example:
from kedro.framework.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.hooks
KedroContext.io
Read-only alias property referring to Kedro’s DataCatalog
for this context.KedroContext.package_name
Property for Kedro project package name. KedroContext.params
Read-only property referring to Kedro’s parameters for this context. KedroContext.pipeline
Read-only property for an instance of Pipeline. KedroContext.pipelines
Read-only property for an instance of Pipeline. 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. KedroContext.run_id
Unique identifier for a run / journal record, defaults to None. 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, extra_params=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 for running the pipeline. If not specified, it defaults to “local”. - extra_params (
Optional
[Dict
[str
,Any
]]) – Optional dictionary containing extra project parameters. If specified, will update (and therefore take precedence over) the parameters retrieved from the project configuration.
- project_path (
-
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.
-
hooks
= ()
-
io
¶ Read-only alias property referring to Kedro’s
DataCatalog
for this context.Return type: DataCatalog
Returns: DataCatalog defined in catalog.yml.
-
package_name
¶ Property for Kedro project package name.
Return type: str
Returns: Name of Kedro project package.
-
params
¶ Read-only property referring to Kedro’s parameters for this context.
Return type: Dict
[str
,Any
]Returns: - Parameters defined in parameters.yml with the addition of any
- extra parameters passed at initialization.
-
pipeline
¶ Read-only property for an instance of Pipeline.
Return type: Pipeline
Returns: Defined pipeline.
-
pipelines
¶ Read-only property for an instance of Pipeline.
Return type: Dict
[str
,Pipeline
]Returns: A dictionary of defined pipelines.
-
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, from_inputs=None, load_versions=None, pipeline_name=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 thePipeline
. 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 thePipeline
. 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 newPipeline
. - to_nodes (
Optional
[Iterable
[str
]]) – An optional list of node names which should be used as an end point of the newPipeline
. - from_inputs (
Optional
[Iterable
[str
]]) – An optional list of input datasets which should be used as a starting point of the newPipeline
. - load_versions (
Optional
[Dict
[str
,str
]]) – An optional flag to specify a particular dataset version timestamp to load. - pipeline_name (
Optional
[str
]) – Name of thePipeline
to execute. Defaults to “__default__”.
Raises: KedroContextError
– If the resultingPipeline
is empty or incorrect tags are provided.Exception
– Any uncaught exception will be re-raised after being passed to``on_pipeline_error``.
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.- tags (
-
run_id
¶ Unique identifier for a run / journal record, defaults to None. If run_id is None, save_version will be used instead.
Return type: Union
[None
,str
]
-