Implementation:PrefectHQ Prefect Hello World Example
| 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
- Repository: PrefectHQ_Prefect
- File: examples/hello_world.py
- Lines: 1-111
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)