Quickstart
Get started with Prefect, the easiest way to orchestrate and observe your data pipelines
Prefect is an orchestration and observability platform that empowers developers to build and scale workflows 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
To install Prefect with pip, run:
See Install Prefect for more details on installation.
Connect to a Prefect API
Connect to a Prefect API:
-
Start a local API server:
-
Open the Prefect dashboard in your browser at http://localhost:4200.
Convert your script to a Prefect workflow
The easiest way to convert a Python script into a workflow is to add a @flow
decorator to the script’s entrypoint.
This will create a corresponding flow.
Adding @task
decorators to any 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 then record these dependencies and states as it orchestrates these tasks.
The log_prints=True
argument provided to the @flow
decorator automatically converts any print
statements within the function to INFO
level logs.
Run your flow
You can run your Prefect flow just as you would a Python script:
Prefect automatically tracks the state of the flow run and logs the output, which can be viewed directly in the terminal or in the UI.
Create a work pool
Running a flow locally is a good start, but most use cases require a remote execution environment. A work pool is the most common interface for deploying flows to remote infrastructure.
Deploy your flow to a self-hosted Prefect server instance using a Process
work pool.
All flow runs submitted to this work pool will run in a local subprocess (the mechanics are similar for other work pool types that run on remote infrastructure).
-
Create a
Process
work pool: -
Verify that the work pool exists:
-
Start a worker to poll the work pool:
You can also choose from other work pool types.
Deploy and schedule your flow
A deployment is used to determine when, where, and how a flow should run. Deployments elevate flows to remotely configurable entities that have their own API.
-
Create a deployment in code:
create_deployment.pyYou 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.
-
Run the script to create the deployment:
Check the logs to ensure your deployment was created:
-
Schedule a run for the deployment:
Soon you should see the flow run graph and logs on the Flow Run page in the UI. Logs are also streamed to the terminal.
Next steps
You’ve seen how to move from a Python script to a scheduled, observable, remotely orchestrated workflow with Prefect. Now consider reading:
- Write flows
- Write tasks
- Cloud and server
- Manage infrastructure with work pools to learn about running workflows on Kubernetes, Docker, and serverless infrastructure.
Need help? Book a meeting with a Prefect Product Advocate to get your questions answered.
Was this page helpful?