Named Outputs

By default, Flyte names the outputs of a task or workflow using a standardized convention. All outputs are named as o1, o2, o3, ... o<n>. where o is the standard prefix and 1, 2, .. <n> is the index position within the return values.

It is also possible to name the outputs of a task or a workflow so that it’s easier to refer to them while debugging or visualizing them in the UI. This is not possible to do natively in Python, so Flytekit provides an alternate way using typing.NamedTuple.

The following example shows how to name outputs of a task and a workflow.

import typing

from flytekit import task, workflow

Named outputs can be declared inline as in the following task signature.


Note the name of the NamedTuple does not matter, but the names and types of the variables do. We used a a default name like OP. Also named tuples can be inline, but by convention we prefer to declare them, as pypy linter errors can be avoided this way.

def say_hello() -> typing.NamedTuple("OP", greet=str):
hello_output = typing.NamedTuple("OP", greet=str)

def say_hello() -> hello_output:
    return hello_output("hello world")

You can also declare the namedtuple ahead of time and then use it in the signature as follows:

wf_outputs = typing.NamedTuple("OP2", greet1=str, greet2=str)

As shown in this example, you can now refer to the declared namedtuple. Also as you can see in the workflow, say_hello returns a tuple, but as with other tuples, you can simply unbox it inline. Also the workflow itself returns a tuple. You can also construct the tuple as you return.


Note that we are de-referencing the individual task execution outputs because named-outputs use named-tuples which are tuples that need to be de-referenced.

def my_wf() -> wf_outputs:
    return wf_outputs(say_hello().greet, say_hello().greet)

The workflow can be executed as usual.

if __name__ == "__main__":
    print(f"Running my_wf() {my_wf()}")

Total running time of the script: ( 0 minutes 0.000 seconds)

Gallery generated by Sphinx-Gallery