Quickly view the structure of your flow using its visualize() method. Calling this method attempts to produce a schematic diagram of your flow and tasks without actually running your flow code.

Functions and code outside of flows or tasks will still be run when calling visualize(). This may have unintended consequences. Place your code into tasks to avoid unintended execution.

To use the visualize() method, you must havae Graphviz installed and on your PATH. Please install Graphviz from http://www.graphviz.org/download/.

Just installing the graphviz python package is not sufficient.

from prefect import flow, task

@task(name="Print Hello")
def print_hello(name):
    msg = f"Hello {name}!"
    print(msg)
    return msg

@task(name="Print Hello Again")
def print_hello_again(name):
    msg = f"Hello {name}!"
    print(msg)
    return msg

@flow(name="Hello Flow")
def hello_world(name="world"):
    message = print_hello(name)
    message2 = print_hello_again(message)

if __name__ == "__main__":
    hello_world.visualize()

A simple flow visualized with the .visualize() method

Prefect cannot automatically produce a schematic for dynamic workflows, such as those with loops or if/else control flow. In this case, you can provide tasks with mock return values for use in the visualize() call.

from prefect import flow, task
@task(viz_return_value=[4])
def get_list():
    return [1, 2, 3]

@task
def append_one(n):
    return n.append(6)

@flow
def viz_return_value_tracked():
    l = get_list()
    for num in range(3):
        l.append(5)
        append_one(l)

if __name__ == "__main__":
    viz_return_value_tracked.visualize()

A flow with return values visualized with the .visualize() method