Each task can generate output data. And those data are passed to the following Tasks. These outputs can be variables or files stored inside Kestra's internal storage.
Accessing outputs
Task output can be accessed during the flow using the {{ outputs['task-id'] }}
syntax. If your task's id contains no -
, you can directly use {{ outputs.taskId }}
.
You can also check the outputs of your tasks in the Output tab of an execution. Very useful for debugging your flow.
Use output in your flow
In our example, we will use the output of the download
task to do some Python analytics. In the inputFiles
of the Python task, we define a main.py, the Python script executed. We also add a data.csv file, the output of the download
task.
yaml
- id: analyze-data
type: io.kestra.core.tasks.scripts.Python
inputFiles:
data.csv: "{{outputs.download.uri}}"
main.py: |
import pandas as pd
from kestra import Kestra
data = pd.read_csv("data.csv", sep=";")
data.info()
sumOfConsumption = data['conso'].sum()
Kestra.outputs({'sumOfConsumption': int(sumOfConsumption)})
requirements:
- pandas
Click here to see the full flow
yaml
id: kestra-tutorial
namespace: io.kestra.tutorial
labels:
env: PRD
description: |
# Kestra Tutorial
As you notice, we can use markdown here.
tasks:
- id: download
type: io.kestra.plugin.fs.http.Download
uri: "https://gist.githubusercontent.com/tchiotludo/2b7f28f4f507074e60150aedb028e074/raw/6b6348c4f912e79e3ffccaf944fd019bf51cba30/conso-elec-gaz-annuelle-par-naf-agregee-region.csv"
- id: analyze-data
type: io.kestra.core.tasks.scripts.Python
inputFiles:
data.csv: "{{outputs.download.uri}}"
main.py: |
import pandas as pd
from kestra import Kestra
data = pd.read_csv("data.csv", sep=";")
data.info()
sumOfConsumption = data['conso'].sum()
Kestra.outputs({'sumOfConsumption': int(sumOfConsumption)})
requirements:
- pandas