Pipeline
kedro.pipeline.pipeline ¶
A Pipeline is a collection of Node objects which can be executed as
a Directed Acyclic Graph, sequentially or in parallel. The Pipeline class
offers quick access to input dependencies,
produced outputs and execution order.
CircularDependencyError ¶
Bases: Exception
Raised when it is not possible to provide a topological execution order for nodes, due to a circular dependency existing in the node definition.
ConfirmNotUniqueError ¶
Bases: Exception
Raised when two or more nodes that are part of the same pipeline attempt to confirm the same dataset.
OutputNotUniqueError ¶
Bases: Exception
Raised when two or more nodes that are part of the same pipeline produce outputs with the same name.
Pipeline ¶
Pipeline(nodes, *, inputs=None, outputs=None, parameters=None, tags=None, namespace=None, prefix_datasets_with_namespace=True)
A Pipeline defined as a collection of Node objects. This class
treats nodes as part of a graph representation and provides inputs,
outputs and execution order.
Parameters:
-
nodes(Iterable[Node | Pipeline] | Pipeline) –The iterable of nodes the
Pipelinewill be made of. If you provide pipelines among the list of nodes, those pipelines will be expanded and all their nodes will become part of this new pipeline. -
inputs(str | set[str] | dict[str, str] | None, default:None) –A name or collection of input names to be exposed as connection points to other pipelines upstream. This is optional; if not provided, the pipeline inputs are automatically inferred from the pipeline structure. When str or set[str] is provided, the listed input names will stay the same as they are named in the provided pipeline. When dict[str, str] is provided, current input names will be mapped to new names. Must only refer to the pipeline's free inputs.
-
outputs(str | set[str] | dict[str, str] | None, default:None) –A name or collection of names to be exposed as connection points to other pipelines downstream. This is optional; if not provided, the pipeline outputs are automatically inferred from the pipeline structure. When str or set[str] is provided, the listed output names will stay the same as they are named in the provided pipeline. When dict[str, str] is provided, current output names will be mapped to new names. Can refer to both the pipeline's free outputs, as well as intermediate results that need to be exposed.
-
parameters(str | set[str] | dict[str, str] | None, default:None) –A name or collection of parameters to namespace. When str or set[str] are provided, the listed parameter names will stay the same as they are named in the provided pipeline. When dict[str, str] is provided, current parameter names will be mapped to new names. The parameters can be specified without the
params:prefix. -
tags(str | Iterable[str] | None, default:None) –Optional set of tags to be applied to all the pipeline nodes.
-
namespace(str | None, default:None) –A prefix to give to all dataset names, except those explicitly named with the
inputs/outputsarguments, and parameter references (params:andparameters). -
prefix_datasets_with_namespace(bool, default:True) –A flag to specify if the inputs, outputs, and parameters of the nodes should be prefixed with the namespace. It is set to True by default. It is useful to turn off when namespacing is used for grouping nodes for deployment purposes.
Raises:
-
ValueError–When an empty list of nodes is provided, or when not all nodes have unique names.
-
CircularDependencyError–When visiting all the nodes is not possible due to the existence of a circular dependency.
-
OutputNotUniqueError–When multiple
Nodeinstances produce the same output. -
ConfirmNotUniqueError–When multiple
Nodeinstances attempt to confirm the same dataset. -
PipelineError–When inputs, outputs or parameters are incorrectly specified, or they do not exist on the original pipeline.
Example:
from kedro.pipeline import Pipeline
from kedro.pipeline import node
# In the following scenario first_ds and second_ds
# are datasets provided by io. Pipeline will pass these
# datasets to first_node function and provides the result
# to the second_node as input.
def first_node(first_ds, second_ds):
return dict(third_ds=first_ds + second_ds)
def second_node(third_ds):
return third_ds
pipeline = Pipeline(
[
node(first_node, ["first_ds", "second_ds"], ["third_ds"]),
node(second_node, dict(third_ds="third_ds"), "fourth_ds"),
]
)
pipeline.describe()
Source code in kedro/pipeline/pipeline.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 | |
grouped_nodes
cached
property
¶
grouped_nodes
Return a list of the pipeline nodes in topologically ordered groups, i.e. if node A needs to be run before node B, it will appear in an earlier group.
Returns:
-
list[list[Node]]–The pipeline nodes in topologically ordered groups.
node_dependencies
cached
property
¶
node_dependencies
nodes
cached
property
¶
nodes
Return a list of the pipeline nodes in topological order, i.e. if node A needs to be run before node B, it will appear earlier in the list.
Returns:
-
list[Node]–The list of all pipeline nodes in topological order.
__repr__ ¶
__repr__()
Pipeline ([node1, ..., node10 ...], name='pipeline_name')
Source code in kedro/pipeline/pipeline.py
367 368 369 370 371 372 373 374 375 376 377 | |
all_inputs ¶
all_inputs()
All inputs for all nodes in the pipeline.
Returns:
-
set[str]–All node input names as a Set.
Source code in kedro/pipeline/pipeline.py
404 405 406 407 408 409 410 411 | |
all_outputs ¶
all_outputs()
All outputs of all nodes in the pipeline.
Returns:
-
set[str]–All node outputs.
Source code in kedro/pipeline/pipeline.py
413 414 415 416 417 418 419 420 | |
datasets ¶
datasets()
The names of all datasets used by the Pipeline,
including inputs and outputs.
Returns:
-
set[str]–The set of all pipeline datasets.
Source code in kedro/pipeline/pipeline.py
451 452 453 454 455 456 457 458 459 | |
describe ¶
describe(names_only=True)
Obtain the order of execution and expected free input variables in a loggable pre-formatted string. The order of nodes matches the order of execution given by the topological sort.
Parameters:
-
names_only(bool, default:True) –The flag to describe names_only pipeline with just node names.
Example:
pipeline = Pipeline([...])
logger = logging.getLogger(__name__)
logger.info(pipeline.describe())
After invocation the following will be printed as an info level log statement: ::
#### Pipeline execution order ####
Inputs: C, D
func1([C]) -> [A]
func2([D]) -> [B]
func3([A, D]) -> [E]
Outputs: B, E
##################################
Returns:
-
str–The pipeline description as a formatted string.
Source code in kedro/pipeline/pipeline.py
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 | |
filter ¶
filter(tags=None, from_nodes=None, to_nodes=None, node_names=None, from_inputs=None, to_outputs=None, node_namespaces=None)
Creates a new Pipeline object with the nodes that meet all of the
specified filtering conditions.
The new pipeline object is the intersection of pipelines that meet each filtering condition. This is distinct from chaining multiple filters together.
Parameters:
-
tags(Iterable[str] | None, default:None) –A list of node tags which should be used to lookup the nodes of the new
Pipeline. -
from_nodes(Iterable[str] | None, default:None) –A list of node names which should be used as a starting point of the new
Pipeline. -
to_nodes(Iterable[str] | None, default:None) –A list of node names which should be used as an end point of the new
Pipeline. -
node_names(Iterable[str] | None, default:None) –A list of node names which should be selected for the new
Pipeline. -
from_inputs(Iterable[str] | None, default:None) –A list of inputs which should be used as a starting point of the new
Pipeline -
to_outputs(Iterable[str] | None, default:None) –A list of outputs which should be the final outputs of the new
Pipeline. -
node_namespaces(Iterable[str] | None, default:None) –A list of node namespaces which should be used to select nodes in the new
Pipeline.
Returns:
-
Pipeline–A new
Pipelineobject with nodes that meet all of the specified filtering conditions.
Raises:
-
ValueError–The filtered
Pipelinehas no nodes.
Example:
pipeline = Pipeline(
[
node(func, "A", "B", name="node1"),
node(func, "B", "C", name="node2"),
node(func, "C", "D", name="node3"),
]
)
pipeline.filter(node_names=["node1", "node3"], from_inputs=["A"])
# Gives a new pipeline object containing node1 and node3.
Source code in kedro/pipeline/pipeline.py
965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 | |
from_inputs ¶
from_inputs(*inputs)
Create a new Pipeline object with the nodes which depend
directly or transitively on the provided inputs.
If provided a name, but no format, for a transcoded input, it
includes all the nodes that use inputs with that name, otherwise it
matches to the fully-qualified name only (i.e. name@format).
Parameters:
-
*inputs(str, default:()) –A list of inputs which should be used as a starting point of the new
Pipeline
Raises:
-
ValueError–Raised when any of the given inputs do not exist in the
Pipelineobject.
Returns:
-
Pipeline–A new
Pipelineobject, containing a subset of the nodes of the current one such that only nodes depending directly or transitively on the provided inputs are being copied.
Source code in kedro/pipeline/pipeline.py
802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 | |
from_nodes ¶
from_nodes(*node_names)
Create a new Pipeline object with the nodes which depend
directly or transitively on the provided nodes.
Parameters:
-
*node_names(str, default:()) –A list of node_names which should be used as a starting point of the new
Pipeline.
Raises:
ValueError: Raised when any of the given names do not exist in the
Pipeline object.
Returns:
A new Pipeline object, containing a subset of the nodes of
the current one such that only nodes depending directly or
transitively on the provided nodes are being copied.
Source code in kedro/pipeline/pipeline.py
906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 | |
group_nodes_by ¶
group_nodes_by(group_by='namespace')
Return a list of grouped nodes based on the specified strategy.
Parameters:
-
group_by(str | None, default:'namespace') –Strategy for grouping. Supported values: - "namespace": Groups nodes by their top-level namespace. - None or "none": No grouping, each node is its own group.
Returns:
-
list[GroupedNodes]–A list of GroupedNodes instances.
Source code in kedro/pipeline/pipeline.py
574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 | |
inputs ¶
inputs()
The names of free inputs that must be provided at runtime so that the pipeline is runnable. Does not include intermediate inputs which are produced and consumed by the inner pipeline nodes. Resolves transcoded names where necessary.
Returns:
-
set[str]–The set of free input names needed by the pipeline.
Source code in kedro/pipeline/pipeline.py
428 429 430 431 432 433 434 435 436 437 438 | |
only_nodes ¶
only_nodes(*node_names)
Create a new Pipeline which will contain only the specified
nodes by name.
Parameters:
-
*node_names(str, default:()) –One or more node names. The returned
Pipelinewill only contain these nodes.
Raises:
-
ValueError–When some invalid node name is given.
Returns:
-
Pipeline–A new
Pipeline, containing onlynodes.
Source code in kedro/pipeline/pipeline.py
637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 | |
only_nodes_with_inputs ¶
only_nodes_with_inputs(*inputs)
Create a new Pipeline object with the nodes which depend
directly on the provided inputs.
If provided a name, but no format, for a transcoded input, it
includes all the nodes that use inputs with that name, otherwise it
matches to the fully-qualified name only (i.e. name@format).
Parameters:
-
*inputs(str, default:()) –A list of inputs which should be used as a starting point of the new
Pipeline.
Raises:
-
ValueError–Raised when any of the given inputs do not exist in the
Pipelineobject.
Returns:
-
Pipeline–A new
Pipelineobject, containing a subset of the nodes of the current one such that only nodes depending directly on the provided inputs are being copied.
Source code in kedro/pipeline/pipeline.py
776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 | |
only_nodes_with_namespaces ¶
only_nodes_with_namespaces(node_namespaces)
Creates a new Pipeline containing only nodes with the specified
namespaces.
Parameters:
-
node_namespaces(list[str]) –A list of node namespaces.
Raises:
-
ValueError–When pipeline contains no nodes with the specified namespaces.
Returns:
-
Pipeline–A new
Pipelinecontaining nodes with the specified namespaces.
Source code in kedro/pipeline/pipeline.py
676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 | |
only_nodes_with_outputs ¶
only_nodes_with_outputs(*outputs)
Create a new Pipeline object with the nodes which are directly
required to produce the provided outputs.
If provided a name, but no format, for a transcoded dataset, it
includes all the nodes that output to that name, otherwise it matches
to the fully-qualified name only (i.e. name@format).
Parameters:
-
*outputs(str, default:()) –A list of outputs which should be the final outputs of the new
Pipeline.
Raises:
-
ValueError–Raised when any of the given outputs do not exist in the
Pipelineobject.
Returns:
-
Pipeline–A new
Pipelineobject, containing a subset of the nodes of the -
Pipeline–current one such that only nodes which are directly required to
-
Pipeline–produce the provided outputs are being copied.
Source code in kedro/pipeline/pipeline.py
842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 | |
only_nodes_with_tags ¶
only_nodes_with_tags(*tags)
Creates a new Pipeline object with the nodes which contain any
of the provided tags. The resulting Pipeline is empty if no tags
are provided.
Parameters:
-
*tags(str, default:()) –A list of node tags which should be used to lookup the nodes of the new
Pipeline.
Returns:
Pipeline: A new Pipeline object, containing a subset of the
nodes of the current one such that only nodes containing any
of the tags provided are being copied.
Source code in kedro/pipeline/pipeline.py
948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 | |
outputs ¶
outputs()
The names of outputs produced when the whole pipeline is run. Does not include intermediate outputs that are consumed by other pipeline nodes. Resolves transcoded names where necessary.
Returns:
-
set[str]–The set of final pipeline outputs.
Source code in kedro/pipeline/pipeline.py
440 441 442 443 444 445 446 447 448 449 | |
tag ¶
tag(tags)
Tags all the nodes in the pipeline.
Parameters:
-
tags(str | Iterable[str]) –The tags to be added to the nodes.
Returns:
-
Pipeline–New
Pipelineobject with nodes tagged.
Source code in kedro/pipeline/pipeline.py
1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 | |
to_json ¶
to_json()
Return a json representation of the pipeline.
Source code in kedro/pipeline/pipeline.py
1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 | |
to_nodes ¶
to_nodes(*node_names)
Create a new Pipeline object with the nodes required directly
or transitively by the provided nodes.
Parameters:
-
*node_names(str, default:()) –A list of node_names which should be used as an end point of the new
Pipeline.
Raises:
ValueError: Raised when any of the given names do not exist in the
Pipeline object.
Returns:
A new Pipeline object, containing a subset of the nodes of the
current one such that only nodes required directly or
transitively by the provided nodes are being copied.
Source code in kedro/pipeline/pipeline.py
927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 | |
to_outputs ¶
to_outputs(*outputs)
Create a new Pipeline object with the nodes which are directly
or transitively required to produce the provided outputs.
If provided a name, but no format, for a transcoded dataset, it
includes all the nodes that output to that name, otherwise it matches
to the fully-qualified name only (i.e. name@format).
Parameters:
-
*outputs(str, default:()) –A list of outputs which should be the final outputs of the new
Pipeline.
Raises:
-
ValueError–Raised when any of the given outputs do not exist in the
Pipelineobject.
Returns:
-
Pipeline–A new
Pipelineobject, containing a subset of the nodes of the -
Pipeline–current one such that only nodes which are directly or transitively
-
Pipeline–required to produce the provided outputs are being copied.
Source code in kedro/pipeline/pipeline.py
867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 | |
PipelineError ¶
Bases: Exception
Raised when a pipeline is not adapted and integrated appropriately using the helper.
pipeline ¶
pipeline(nodes, *, inputs=None, outputs=None, parameters=None, tags=None, namespace=None, prefix_datasets_with_namespace=True)
Create a Pipeline from a collection of nodes and/or Pipeline\s.
Parameters:
-
nodes(Iterable[Node | Pipeline] | Pipeline) –The nodes the
Pipelinewill be made of. If you provide pipelines among the list of nodes, those pipelines will be expanded and all their nodes will become part of this new pipeline. -
inputs(str | set[str] | dict[str, str] | None, default:None) –A name or collection of input names to be exposed as connection points to other pipelines upstream. This is optional; if not provided, the pipeline inputs are automatically inferred from the pipeline structure. When str or set[str] is provided, the listed input names will stay the same as they are named in the provided pipeline. When dict[str, str] is provided, current input names will be mapped to new names. Must only refer to the pipeline's free inputs.
-
outputs(str | set[str] | dict[str, str] | None, default:None) –A name or collection of names to be exposed as connection points to other pipelines downstream. This is optional; if not provided, the pipeline outputs are automatically inferred from the pipeline structure. When str or set[str] is provided, the listed output names will stay the same as they are named in the provided pipeline. When dict[str, str] is provided, current output names will be mapped to new names. Can refer to both the pipeline's free outputs, as well as intermediate results that need to be exposed.
-
parameters(str | set[str] | dict[str, str] | None, default:None) –A name or collection of parameters to namespace. When str or set[str] are provided, the listed parameter names will stay the same as they are named in the provided pipeline. When dict[str, str] is provided, current parameter names will be mapped to new names. The parameters can be specified without the
params:prefix. -
tags(str | Iterable[str] | None, default:None) –Optional set of tags to be applied to all the pipeline nodes.
-
namespace(str | None, default:None) –A prefix to give to all dataset names, except those explicitly named with the
inputs/outputsarguments, and parameter references (params:andparameters). -
prefix_datasets_with_namespace(bool, default:True) –A flag to specify if the inputs and outputs of the nodes should be prefixed with the namespace. It is set to True by default. It is useful to turn off when namespacing is used for grouping nodes for deployment purposes.
Raises:
-
PipelineError–When inputs, outputs or parameters are incorrectly specified, or they do not exist on the original pipeline.
-
ValueError–When underlying pipeline nodes inputs/outputs are not any of the expected types (str, dict, list, or None).
Returns:
-
Pipeline–A new
Pipelineobject.
Source code in kedro/pipeline/pipeline.py
1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 | |