kedro.framework.session.session.KedroSession¶
- class kedro.framework.session.session.KedroSession(session_id, package_name=None, project_path=None, save_on_close=False, conf_source=None)[source]¶
KedroSessionis the object that is responsible for managing the lifecycle of a Kedro run. Use KedroSession.create() as a context manager to construct a new KedroSession with session data provided (see the example below).Example:
from kedro.framework.session import KedroSession from kedro.framework.startup import bootstrap_project from pathlib import Path # If you are creating a session outside of a Kedro project (i.e. not using # `kedro run` or `kedro jupyter`), you need to run `bootstrap_project` to # let Kedro find your configuration. bootstrap_project(Path("<project_root>")) with KedroSession.create() as session: session.run()
Attributes
Return a copy of internal store.
Methods
close()Close the current session and save its store to disk if save_on_close attribute is True.
create([package_name, project_path, ...])Create a new instance of
KedroSessionwith the session data.An instance of the project context.
run([pipeline_name, tags, runner, ...])Runs the pipeline with a specified runner.
- close()[source]¶
Close the current session and save its store to disk if save_on_close attribute is True.
- classmethod create(package_name=None, project_path=None, save_on_close=True, env=None, extra_params=None, conf_source=None)[source]¶
Create a new instance of
KedroSessionwith the session data.- Parameters:
package_name (str) – Package name for the Kedro project the session is created for. The package_name argument will be removed in Kedro 0.19.0.
project_path (Path | str | None) – Path to the project root directory. Default is current working directory Path.cwd().
save_on_close (bool) – Whether or not to save the session when it’s closed.
conf_source (str | None) – Path to a directory containing configuration
env (str) – Environment for the KedroContext.
extra_params (dict[str, Any]) – Optional dictionary containing extra project parameters for underlying KedroContext. If specified, will update (and therefore take precedence over) the parameters retrieved from the project configuration.
- Return type:
- Returns:
A new
KedroSessioninstance.
- run(pipeline_name=None, tags=None, runner=None, node_names=None, from_nodes=None, to_nodes=None, from_inputs=None, to_outputs=None, load_versions=None, namespace=None)[source]¶
Runs the pipeline with a specified runner.
- Parameters:
pipeline_name – Name of the pipeline that is being run.
tags – 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 – An optional parameter specifying the runner that you want to run the pipeline with.
node_names – 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 – An optional list of node names which should be used as a starting point of the new
Pipeline.to_nodes – An optional list of node names which should be used as an end point of the new
Pipeline.from_inputs – An optional list of input datasets which should be used as a starting point of the new
Pipeline.to_outputs – An optional list of output datasets which should be used as an end point of the new
Pipeline.load_versions – An optional flag to specify a particular dataset version timestamp to load.
namespace – The namespace of the nodes that is being run.
- Raises:
ValueError – If the named or __default__ pipeline is not defined by register_pipelines.
Exception – Any uncaught exception during the run will be re-raised after being passed to
on_pipeline_errorhook.KedroSessionError – If more than one run is attempted to be executed during a single session.
- 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 store: dict[str, Any]¶
Return a copy of internal store.