{"id":1633,"library":"prefect","title":"Prefect Workflow Orchestration","description":"Prefect is an open-source workflow orchestration and management system that allows users to build, run, and monitor data pipelines. It provides a robust framework for defining workflows as Python code, complete with task dependencies, retries, caching, and state management. The current stable version is 3.6.25, with frequent nightly development builds and stable releases typically every few weeks.","status":"active","version":"3.6.25","language":"en","source_language":"en","source_url":"https://github.com/PrefectHQ/prefect","tags":["workflow","orchestration","data engineering","ETL","automation","observability"],"install":[{"cmd":"pip install prefect","lang":"bash","label":"Install Prefect"}],"dependencies":[],"imports":[{"symbol":"flow","correct":"from prefect import flow"},{"symbol":"task","correct":"from prefect import task"},{"symbol":"serve","correct":"from prefect import serve"},{"note":"Deployment class is located in `prefect.deployments` since Prefect 2.","wrong":"from prefect import Deployment","symbol":"Deployment","correct":"from prefect.deployments import Deployment"}],"quickstart":{"code":"import os\nfrom prefect import flow, task, serve\n\n@task\ndef greet_task(name: str):\n    \"\"\"A simple task that prints a greeting.\"\"\"\n    print(f\"Hello from task, {name}!\")\n    return f\"Task processed: {name}\"\n\n@flow(log_prints=True)\ndef my_orchestrated_flow(name: str = \"World\"):\n    \"\"\"A flow that uses the greet_task and prints its result.\"\"\"\n    print(f\"Flow starting for {name}...\")\n    task_result = greet_task(name)\n    print(f\"Flow received result: {task_result}\")\n    return f\"Flow completed for {name}\"\n\nif __name__ == \"__main__\":\n    # To connect to Prefect Cloud, set these environment variables:\n    # os.environ['PREFECT_API_URL'] = os.environ.get('PREFECT_API_URL', 'https://api.prefect.cloud/api/accounts/.../workspaces/...')\n    # os.environ['PREFECT_API_KEY'] = os.environ.get('PREFECT_API_KEY', 'pf_...')\n\n    # To run a flow and see it in the UI, it must be 'served' or deployed.\n    # This starts a local Prefect API server and an agent, then registers the deployment.\n    # Access the UI at http://localhost:4200\n    print(\"Serving 'my_orchestrated_flow' locally. Open http://localhost:4200 in your browser.\")\n    serve(my_orchestrated_flow.to_deployment(name=\"my-first-deployment\", interval=10))\n\n    # To simply run a flow locally without orchestration (not recommended for production):\n    # my_orchestrated_flow(\"Local User\")","lang":"python","description":"This quickstart defines a simple task and a flow that uses it. It then demonstrates how to `serve` the flow, which will start a local Prefect API server and agent, and register the flow as a deployment. This allows you to observe flow runs and their states in the Pref Prefect UI (http://localhost:4200). For connecting to Prefect Cloud, set `PREFECT_API_URL` and `PREFECT_API_KEY` environment variables."},"warnings":[{"fix":"Review the Prefect 2 migration guide and rewrite existing Prefect 1 flows to conform to the new API and concepts. There is no automated upgrade path.","message":"Prefect 2 (current major version) is a complete rewrite and is NOT backward compatible with Prefect 1. Code written for Prefect 1 will not run on Prefect 2 without significant modification. Key concepts like 'projects' were replaced by 'deployments', and the API changed entirely.","severity":"breaking","affected_versions":"All Prefect 2.x.x versions when migrating from Prefect 1.x.x"},{"fix":"Always use `flow.to_deployment()` and then either `serve()` for local development/testing or `prefect deploy` for production environments to register your flow with the Prefect API and enable orchestration.","message":"Running `my_flow()` executes the flow locally as a plain Python function. To leverage Prefect's orchestration features (retries, scheduling, state tracking, UI visibility), flows must be 'deployed'. This is typically done via `flow.to_deployment()` combined with `serve()` or using the `prefect deploy` CLI.","severity":"gotcha","affected_versions":"All Prefect 2.x.x versions"},{"fix":"For local development, use `prefect serve()` to start a temporary server and agent, or run `prefect server start` in a separate terminal. For Prefect Cloud, set the necessary environment variables (`PREFECT_API_URL`, `PREFECT_API_KEY`).","message":"The Prefect UI/API server does not automatically start with `pip install prefect`. For local orchestration and UI access, you must either run `prefect server start` or use `prefect serve()` as demonstrated in the quickstart. If connecting to Prefect Cloud, ensure `PREFECT_API_URL` and `PREFECT_API_KEY` are correctly configured.","severity":"gotcha","affected_versions":"All Prefect 2.x.x versions"},{"fix":"After code changes, re-run your `serve()` script or use the `prefect deploy` CLI command to update the deployment definition.","message":"When modifying a flow's code, you must re-deploy or re-serve the flow for the changes to take effect in your Prefect deployments. Simply saving the Python file is not enough; the updated definition needs to be registered with the Prefect API.","severity":"gotcha","affected_versions":"All Prefect 2.x.x versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}