Set up a development environment
First, download the source code and install an editable copy of the Prefect Python package:ruff check
and ruff format
.
After installation, you can run the test suite with pytest
:
Build the Prefect UIIf you intend to run a local Prefect server during development, first build the UI.
See UI development for instructions.
Developer tooling
The Prefect CLI provides several helpful commands to aid development. Start all services with hot-reloading on code changes (requires installation of UI dependencies):UI development
Developing the Prefect UI requires installation of npm. We recommend using nvm to manage Node.js versions. Once installed, runnvm use
from the root of the Prefect repository to initialize the proper version of npm
and node
.
Start a development UI that reloads on code changes:
prefect server start
):
Docs development
We use Mintlify to host and build the documentation. The main branch of the prefecthq/prefect GitHub repository is used to build the Prefect 3.0rc docs at docs-3.prefect.io temporarily. The 2.x docs are hosted at docs.prefect.io and built from the 2.x branch of prefecthq/prefect. Make sure you have a recent version of Node.js installed. We recommend using nvm to manage Node.js versions.- Clone this repository.
- Run
cd docs
to navigate to the docs directory. - Run
nvm use node
to use the correct Node.js version. - Run
npm i -g mintlify
to install Mintlify. - Run
mintlify dev
to start the development server.
http://localhost:3000
.
See the Mintlify documentation for more information on how install Mintlify, build previews, and use Mintlify’s features while writing docs.
.mdx
files are Markdown files that can contain JavaScript and React components. They are used to create interactive documentation.
Add database migrations
To make changes to a table, first update the SQLAlchemy model insrc/prefect/server/database/orm_models.py
. For example,
to add a new column to the flow_run
table, add a new column to the FlowRun
model:
PREFECT_API_DATABASE_CONNECTION_URL
is set to.
See how to set the database connection URL for
each database type.
To generate a new migration file, run:
add_flow_run_new_column
add_flow_run_new_column_idx
rename_flow_run_old_column_to_new_column
--autogenerate
flag automatically generates a migration file based on the changes to the models.
Always inspect the output of
--autogenerate
--autogenerate
generates a migration file based on the changes to the models. However, it is not perfect. Check
the file to make sure it only includes the changes you want. Additionally, you may need to remove extra statements that
were included and not related to your change.src/prefect/server/database/migrations/versions/
directory. Each database type has its
own subdirectory. For example, the SQLite migrations are stored in src/prefect/server/database/migrations/versions/sqlite/
.
After you inspect the migration file, you can apply the migration to your database by running:
MIGRATION-NOTES.md
to
document your additions.