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. We’ll save this metadata to a Prefect Server.
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.
Was this page helpful?