kedro.framework.context.KedroContext¶
-
class
kedro.framework.context.KedroContext(package_name, project_path, env=None, extra_params=None)[source]¶ KedroContextis the base class which holds the configuration and Kedro’s main functionality.Attributes
Deprecated in favour of settings.CONF_ROOT
Read-only property referring to Kedro’s
DataCatalogfor this context.Read-only property referring to Kedro’s
ConfigLoaderfor this context.Property for the current Kedro environment.
Read-only alias property referring to Kedro’s
DataCatalogfor this context.Property for Kedro project package name.
Read-only property referring to Kedro’s parameters for this context.
Read-only property for an instance of Pipeline.
Read-only property for an instance of Pipeline.
Read-only property containing Kedro’s root project directory.
Unique identifier for a run / journal record, defaults to None.
Methods
run([tags, runner, node_names, from_nodes, …])Runs the pipeline with a specified runner.
-
property
CONF_ROOT¶ Deprecated in favour of settings.CONF_ROOT
- Return type
str- Returns
The root directory of the configuration directory of the project.
- Raises
DeprecationWarning –
-
__init__(package_name, 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
package_name (
str) – Package name for the Kedro project the context is created for.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.
-
property
catalog¶ Read-only property referring to Kedro’s
DataCatalogfor this context.- Return type
DataCatalog- Returns
DataCatalog defined in catalog.yml.
- Raises
KedroContextError – Incorrect
DataCatalogregistered for the project.
-
property
config_loader¶ Read-only property referring to Kedro’s
ConfigLoaderfor this context.- Return type
ConfigLoader- Returns
Instance of ConfigLoader.
- Raises
KedroContextError – Incorrect
ConfigLoaderregistered for the project.
-
property
env¶ Property for the current Kedro environment.
- Return type
str- Returns
Name of the current Kedro environment.
-
property
io¶ Read-only alias property referring to Kedro’s
DataCatalogfor this context.- Return type
DataCatalog- Returns
DataCatalog defined in catalog.yml.
- Raises
KedroContextError – Incorrect
DataCatalogregistered for the project.
-
property
package_name¶ Property for Kedro project package name.
- Return type
str- Returns
Name of Kedro project package.
-
property
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.
-
property
pipeline¶ Read-only property for an instance of Pipeline.
- Return type
Pipeline- Returns
Default pipeline.
- Raises
KedroContextError – If the __default__ pipeline is not defined by register_pipelines.
-
property
pipelines¶ Read-only property for an instance of Pipeline.
- Return type
Dict[str,Pipeline]- Returns
A dictionary of defined pipelines.
-
property
project_path¶ Read-only property containing Kedro’s root project directory.
- Return type
Path- Returns
Project directory.
-
run(tags=None, runner=None, node_names=None, from_nodes=None, to_nodes=None, from_inputs=None, to_outputs=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.to_outputs (
Optional[Iterable[str]]) – An optional list of output datasets which should be used as an end 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 thePipelineto execute. Defaults to “__default__”.
- Raises
KedroContextError – If the resulting
Pipelineis 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.
-
property
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
Optional[str]
-
property