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]¶ KedroSession
is 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
KedroSession
with 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
KedroSession
with the session data.- Parameters
package_name (
Optional
[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 (
Union
[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 (
Optional
[str
]) – Path to a directory containing configurationenv (
Optional
[str
]) – Environment for the KedroContext.extra_params (
Optional
[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
KedroSession
instance.
-
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)[source]¶ Runs the pipeline with a specified runner.
- Parameters
pipeline_name (
Optional
[str
]) – Name of the pipeline that is being run.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.
- 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_error
hook.KedroSessionError – If more than one run is attempted to be executed during a single session.
- 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
store
¶ Return a copy of internal store.
- Return type
Dict
[str
,Any
]
-