Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:PrefectHQ Prefect Hello World Example

From Leeroopedia
Revision as of 16:22, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/PrefectHQ_Prefect_Hello_World_Example.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Knowledge Sources
Domains Orchestration, Getting_Started, Examples
Last Updated 2026-02-09 22:00 GMT

Overview

Introductory example demonstrating the most basic Prefect flow using the `@flow` decorator with `log_prints`, parameters, and tags.

Description

The hello_world.py example is the canonical starting point for new Prefect users. It defines a single `hello` function decorated with `@flow(log_prints=True)` that prints a greeting. The example demonstrates calling the flow with default parameters, custom parameters, and iterating over a list of names. It also shows the use of the `tags` context manager for labeling flow runs in the UI. The file includes extensive inline documentation explaining what happens when a function is decorated with `@flow`.

Usage

Use this example as a template when creating your first Prefect flow. It demonstrates the minimum viable Prefect workflow: decorating a Python function with `@flow`, running it, and observing the automatic logging, state tracking, and UI integration.

Code Reference

Source Location

Signature

@flow(log_prints=True)
def hello(name: str = "Marvin") -> None:
    """Log a friendly greeting."""
    print(f"Hello, {name}!")

Import

from prefect import flow, tags

I/O Contract

Inputs

Name Type Required Description
name str No Name to greet (default: "Marvin")

Outputs

Name Type Description
return None No return value; greeting is printed and logged
Flow run Prefect state Tracked flow run with logs, state, and metadata

Usage Examples

Basic Hello World

from prefect import flow, tags


@flow(log_prints=True)
def hello(name: str = "Marvin") -> None:
    """Log a friendly greeting."""
    print(f"Hello, {name}!")


if __name__ == "__main__":
    # Run with default parameters
    with tags("test"):
        hello()  # Logs: "Hello, Marvin!"

        # Run with custom parameter
        hello("Marvin")

        # Run for multiple people
        crew = ["Zaphod", "Trillian", "Ford"]
        for name in crew:
            hello(name)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment