Skip to main content
Prefect is an orchestration and observability platform that empowers developers to build and scale code quickly. In this quickstart, you will use Prefect to convert the following Python script to a schedulable, observable, resilient, and deployable workflow in minutes:

Install Prefect

Install Prefect.
If needed, see Install Prefect for other options.

Connect to Prefect’s API

Connect to the Prefect API, either Prefect Cloud hosted by us, or a local Prefect server instance:
  1. Head to https://app.prefect.cloud/ and sign in or create a forever-free Prefect Cloud account.
  2. Log in to Prefect Cloud from your development environment:
  3. Choose Log in with a web browser and click the Authorize button in the browser window that opens.
Your CLI is now authenticated with your Prefect Cloud account through a locally-stored API key that expires in 30 days.If you have any issues with browser-based authentication, see the Prefect Cloud docs to learn how to authenticate with a manually created API key.

Convert your script to a Prefect flow

The easiest way to convert a Python script into a workflow is to add a @flow decorator to the script’s entrypoint, the Python function that runs first. Flows are containers for workflow logic as code. They’re the core observable, orchestrated, deployable units of work in Prefect. Adding @task decorators to the functions called by the flow converts them to tasks. Tasks receive metadata about upstream dependencies and the state of those dependencies before they run. Prefect will record these dependencies and states as it orchestrates these tasks when they run.
my_gh_workflow.py
The log_prints=True argument provided to the @flow decorator logs output from print statements within the function.

Run your flow

Run your Prefect flow just as you would a Python script:
Prefect automatically tracks the state of the flow run and logs the output in the UI and CLI.

Create a work pool

Running a flow locally is a good start, but you should use a remote destination for production flows. A work pool is the most common way to do this.
Deploy your flow to Cloud using a managed work pool.
  1. Create a managed work pool:
  2. View your new work pool on the Work Pools page of the UI.

Deploy and schedule your flow

A deployment is used to determine when, where, and how a flow function should run. Deployments elevate flows to remotely configurable entities that have their own API.
  1. Create a deployment script:
    create_deployment.py
    You can store your flow code in nearly any location as long as Prefect can access it. See Where to store your flow code for more details.
  2. Run the script to create the deployment:
    Check the logs to ensure your deployment was created:
  3. Schedule a run for the deployment:
    After a minute or so, you should see the flow run graph and logs on the Flow Run page in the UI. Flow run graph and logs
  4. When you’re done, click the More > Delete button on the Deployments page to stop further scheduled runs.

Next steps

You’ve seen how to move from a Python script to a scheduled, observable, remotely orchestrated workflow with Prefect. Now considering reading:
Need help? Book a meeting with a Prefect Product Advocate to get your questions answered.