Quickstart
Create your first workflow
Prefect is a workflow orchestration tool that helps you build, deploy, run, and monitor data pipelines. It makes complex workflows reliable by tracking dependencies and handling failures gracefully.
In this tutorial, you’ll deploy your first workflow to Prefect — by specifying what code should run, where it should run, and when it should run. Choose your preferred approach below:
Create and login to your Prefect Cloud account.
Prefect uses a database to store workflow metadata.
For the ease of getting started, we’ll use one hosted on Prefect Cloud. To create an account, we need to install prefect-cloud
. We’ll leverage uv
, a modern Python package manager, to do this. Run the following commands in your terminal, after which you’ll be prompted in your browser to create or login to your free Prefect Cloud account.
What code should run?
Let’s start with a boring Python script that fetches a list of customer ids and processes them all in parallel. You can find this code and other examples hosted in our quickstart repository.
This looks like the ordinary Python you’d write, except there is:
- a
@flow
decorator on the script’s entrypoint. - a
@task
decorator on each function called within the flow.
When you run this flow
, Prefect dynamically creates a graph of each task
and the state of their upstream dependencies. This allows Prefect to execute each task
in the right order and, in the case of failure, to recover the state of your workflow and resume from its point of failure.
Let’s run this code locally on your computer. To do that, run the following command in your terminal.
If all went well, you’ll see a link to see its execution graph in the Prefect UI followed by a flurry of state changes and logs as Prefect dynamically discovers and executes your workflow.
Where should it run?
At this point, you’ve successfully run a Prefect flow
locally. Let’s get it running off of your machine! Again, for simplicity,
we’ll deploy this workflow to Prefect’s Serverless Compute (so we don’t have to wrangle any infrastructure). We’ll tell Prefect to clone
https://github.com/PrefectHQ/quickstart
and invoke 01_getting_started.py:main
.
If all went well, you’ve created your first deployed workflow.
Since we now know what code to run and where to run it, this can now be invoked remotely. To do that, run the following command and visit the returned link to see the run’s status in the Prefect UI:
Congrats! You’ve just run your first Prefect workflow remotely.
When should it run?
Now that you’ve deployed and run your workflow remotely, you might want to schedule it to run automatically at specific times. Prefect makes this easy with the prefect-cloud schedule
command.
Let’s schedule our workflow to run every day at 8:00 AM with cron
syntax.
After running the command, your workflow will automatically execute remotely according to the schedule you’ve set.
You can view and manage all your scheduled runs in the Prefect UI.
Create and login to your Prefect Cloud account.
Prefect uses a database to store workflow metadata.
For the ease of getting started, we’ll use one hosted on Prefect Cloud. To create an account, we need to install prefect-cloud
. We’ll leverage uv
, a modern Python package manager, to do this. Run the following commands in your terminal, after which you’ll be prompted in your browser to create or login to your free Prefect Cloud account.
What code should run?
Let’s start with a boring Python script that fetches a list of customer ids and processes them all in parallel. You can find this code and other examples hosted in our quickstart repository.
This looks like the ordinary Python you’d write, except there is:
- a
@flow
decorator on the script’s entrypoint. - a
@task
decorator on each function called within the flow.
When you run this flow
, Prefect dynamically creates a graph of each task
and the state of their upstream dependencies. This allows Prefect to execute each task
in the right order and, in the case of failure, to recover the state of your workflow and resume from its point of failure.
Let’s run this code locally on your computer. To do that, run the following command in your terminal.
If all went well, you’ll see a link to see its execution graph in the Prefect UI followed by a flurry of state changes and logs as Prefect dynamically discovers and executes your workflow.
Where should it run?
At this point, you’ve successfully run a Prefect flow
locally. Let’s get it running off of your machine! Again, for simplicity,
we’ll deploy this workflow to Prefect’s Serverless Compute (so we don’t have to wrangle any infrastructure). We’ll tell Prefect to clone
https://github.com/PrefectHQ/quickstart
and invoke 01_getting_started.py:main
.
If all went well, you’ve created your first deployed workflow.
Since we now know what code to run and where to run it, this can now be invoked remotely. To do that, run the following command and visit the returned link to see the run’s status in the Prefect UI:
Congrats! You’ve just run your first Prefect workflow remotely.
When should it run?
Now that you’ve deployed and run your workflow remotely, you might want to schedule it to run automatically at specific times. Prefect makes this easy with the prefect-cloud schedule
command.
Let’s schedule our workflow to run every day at 8:00 AM with cron
syntax.
After running the command, your workflow will automatically execute remotely according to the schedule you’ve set.
You can view and manage all your scheduled runs in the Prefect UI.
Install Prefect and start the server
If you’re using Prefect Open Source, you’ll run a server that backs your workflows. Install Prefect and start your local server:
If you prefer to run your Prefect server in a Docker container, you can use the following command:
Both commands start a server at http://localhost:4200
. Keep this process running for this tutorial.
What code should run?
Let’s start with a boring Python script that fetches a list of customer ids and processes them all in parallel. You can find this code and other examples hosted in our quickstart repository.
This looks like the ordinary Python you’d write, except there is:
- a
@flow
decorator on the script’s entrypoint. - a
@task
decorator on each function called within the flow.
When you run this flow
, Prefect dynamically creates a graph of each task
and the state of their upstream dependencies. This allows Prefect to execute each task
in the right order and, in the case of failure, to recover the state of your workflow and resume from its point of failure.
Let’s run this code locally on your computer. To do that, run the following command in your terminal (in a new terminal window, keeping the server running):
If all went well, you’ll see a link to see its execution graph in the Prefect UI followed by a flurry of state changes and logs as Prefect dynamically discovers and executes your workflow.
Where should it run?
At this point, you’ve successfully run a Prefect flow
locally. Let’s set up a simple deployment by updating the file to use .serve()
:
Now run the updated file:
This starts a process listening for scheduled runs. You can now trigger the flow from the Prefect UI or programmatically.
When should it run?
Now let’s schedule your workflow to run automatically. Update the file to add a cron schedule:
Run the updated file:
Your workflow will now run automatically according to the schedule while the serve process is running.
Next steps
Now that you’ve created your first workflow, explore Prefect’s features to enable more sophisticated workflows.
- Learn more about flows and tasks.
- Learn more about deployments.
- Learn more about work pools.
- Learn how to run work concurrently.