pip install prefect★Python 3.9+. Bundles the CLI, an embedded SQLite-backed server, and the UI.from prefect import flow @flow def pipeline(name: str): print(f"hello {name}") if __name__ == "__main__": pipeline("world")★A flow is any function wrapped in@flow. Call it like normal Python — Prefect creates a tracked flow run with logs, timing, and state.@flow(name="etl", log_prints=True, retries=2) def etl(): ...★Flow options:name,retries/retry_delay_seconds,log_prints(captureprint),timeout_seconds,description.prefect server start # local UI at http://127.0.0.1:4200Run the self-hosted server + UI to see runs. Or connect to Prefect Cloud (card 11).
from prefect import flow, task @task def extract(url): return requests.get(url).json() @flow def etl(): data = extract("https://api/x")★Tasks are the retriable, cacheable units. Call them from inside a flow — each call is a tracked task run.fut = extract.submit(url) # run concurrently, returns a future result = fut.result()★.submit()runs a task in the flow's task runner (concurrent by default) and returns a future;.result()blocks for the value.results = extract.map([u1, u2, u3]) # fan out over an iterable★.map()spawns one task run per item — parallel fan-out without writing a loop.# calling a @task outside a @flow just runs the functionnoteTasks orchestrate only within a flow. Outside one they execute as plain functions (no tracking/retries).
@task(retries=3, retry_delay_seconds=[1, 10, 60])★Automatic retries with fixed or backoff delays.retry_condition_fnto retry only on certain failures.from prefect.cache_policies import INPUTS, TASK_SOURCE @task(cache_policy=INPUTS + TASK_SOURCE, cache_expiration=timedelta(hours=1))★Caching: skip re-running a task when its inputs (and code) are unchanged — keyed by acache_policy. Big win for expensive/idempotent steps.from prefect import get_run_logger logger = get_run_logger(); logger.info("processed %d rows", n)★Use the run logger so messages show in the UI attached to the run (or setlog_prints=Trueon the flow).@task(tags=["db"], timeout_seconds=30)Tags drive concurrency limits (card 5); timeouts fail long-hanging tasks.