A tutorial to introduce users to Flyte v2 features through examples
Prereqs: Python 3.10+.
If you don't have uv
:
curl -fsSL https://astral.sh/uv/install.sh | sh
Then install dependencies declared in pyproject.toml
:
uv sync
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
pip install -e .
Running examples:
- Use
flyte run ...
from your venv, or prefix withuv run
if using uv. - Ensure your Flyte CLI is configured for your project/domain. You can pass
-p <project> -d <domain>
to the command if needed.
Command:
flyte run 1_hello_world/hello_polyglot.py main --letter e
What it does:
- Fans out dynamically across languages from
polyglot-hello
whose primary/alias code starts with the given letter. - Runs
hello_for_code
in parallel viaflyte.map
, returning a mapping of language code → greeting. - Validates
letter
(requires a single alphabetic character).
Tip: change --letter
(e.g., p
, s
, f
) to see different sets.
Command:
flyte run 2_failure_handling/oomer.py failure_recovery
What it does:
- Intentionally triggers an OOM in
oomer
(allocates a very large list) with small default memory. - Catches
flyte.errors.OOMError
and retries the same task with higher memory via.override(resources=...)
. - Always runs
always_succeeds()
in afinally
block and returns its result to demonstrate cleanup and recovery.
Command:
flyte run 3_agents/smolagent.py main --goal "Make a peanut butter and jelly sandwich"
What it does:
- Builds a simple plan (steps with
deps
) inget_plan
, then executes it inexecute_plan
respecting dependencies. - Runs ready steps concurrently, grouping iterations with
flyte.group
, and aggregates results by step id. - Uses a reusable task environment (single warm replica) and a preinstalled image dependency for faster iteration.
Try changing --goal
to explore different prints/flow; the toy plan remains the same to showcase orchestration.
Command:
flyte run 4_reports/run_all.py main
What it does:
- Orchestrates all report generators concurrently: globe visualization (Three.js), interactive dashboard (Chart.js/D3), 3D scatter (Plotly), satellite images gallery, protein 3D viewer, and a YouTube embed page.
- Each task emits a rich HTML report via
flyte.report
;run_all
simply gathers them so you can open each artifact from the Union UI.