Hello, World!

Tags: Basic

Let’s write a Flyte workflow() that invokes a task() to generate the output “Hello, World!”.

Flyte tasks are the core building blocks of larger, more complex workflows. Workflows compose multiple tasks – or other workflows – into meaningful steps of computation to produce some useful set of outputs or outcomes.

Note

To clone and run the example code on this page, see the Flytesnacks repo.

To begin, import task and workflow from the flytekit library:

basics/hello_world.py
from flytekit import task, workflow

Define a task that produces the string “Hello, World!”. Simply using the @task decorator to annotate the Python function:

basics/hello_world.py
@task
def say_hello() -> str:
    return "Hello, World!"

You can handle the output of a task in the same way you would with a regular Python function. Store the output in a variable and use it as a return value for a Flyte workflow:

basics/hello_world.py
@workflow
def hello_world_wf() -> str:
    res = say_hello()
    return res

Run the workflow by simply calling it like a Python function:

basics/hello_world.py
if __name__ == "__main__":
    print(f"Running hello_world_wf() {hello_world_wf()}")

Next, let’s delve into the specifics of tasks, workflows and launch plans.