24
loading...
This website collects cookies to deliver better user experience
pip install kedro
conda install -c conda-forge kedro
# importing the library
from kedro.pipeline import node
# Preparing the first "node"
def return_greeting():
return "Hello"
#defining the node that will return
return_greeting_node = node(func=return_greeting, inputs=None, outputs="my_salutation")
#importing the library
from kedro.pipeline import Pipeline
# Assigning "nodes" to "pipeline"
pipeline = Pipeline([return_greeting_node, join_statements_node])
#importing the library
from kedro.io import DataCatalog, MemoryDataSet
# Preparing the "data catalog"
data_catalog = DataCatalog({"my_salutation": MemoryDataSet()})
Kedro first performs return_greeting_node. This performs return_greeting, which receives no input, but produces the string “Hello”.
The output string is stored in the MemoryDataSet called my_salutation. Kedro then executes the second node, join_statements_node.
This loads the my_salutation dataset and injects it into the join_statements function.
The function joins the incoming greeting with “Kedro!” to form the output string “Hello Kedro!”
The pipeline output is returned in a dictionary with the key my_message.
"""Contents of the hello_kedro.py file"""
from kedro.io import DataCatalog, MemoryDataSet
from kedro.pipeline import node, Pipeline
from kedro.runner import SequentialRunner
# Prepare the "data catalog"
data_catalog = DataCatalog({"my_salutation": MemoryDataSet()})
# Prepare the first "node"
def return_greeting():
return "Hello"return_greeting_node = node(return_greeting, inputs=None, outputs="my_salutation")
# Prepare the second "node"
def join_statements(greeting):
return f"{greeting} Kedro!"join_statements_node = node(
join_statements, inputs="my_salutation", outputs="my_message"
)
# Assign "nodes" to a "pipeline"
pipeline = Pipeline([return_greeting_node, join_statements_node])
# Create a "runner" to run the "pipeline"
runner = SequentialRunner()
# Execute a pipeline
print(runner.run(pipeline, data_catalog))
python hello_kedro.py
{‘my_message’: ‘Hello Kedro!’}