Skip to main content

Prefect Deployments Toolkit

PyPI PyPI Downloads

A lightweight CLI toolkit for managing Prefect deployment lifecycles in CI/CD pipelines. It detects deployments that were added, modified, or removed between two git references, and applies (creates, updates, or deletes) those deployments against Prefect Cloud or a self-hosted Prefect server — via either the Prefect CLI or direct REST API calls.

Built for teams running many Prefect flows out of a monorepo, where each deployment is defined in its own YAML file alongside a shared prefect_base.yaml, and CI needs to figure out which deployments actually changed before re-registering them.

Features

  • Change detection — diff deployments between two git refs (a merge request source vs. target branch, or HEAD~1 vs. HEAD after a merge) and get back exactly which deployments were added, modified, or removed.
  • Unified push / pull-request logic — one code path handles both pull_request (compare local files against a fetched base branch) and push/pull_request_target (compare HEAD~1 against HEAD) event styles.
  • Dual deploy backends — apply deployments using the prefect CLI as a subprocess, or bypass it entirely with direct REST API calls for faster, more controllable deploys. Both backends work against Prefect Cloud and self-hosted/OSS Prefect servers.
  • Dev/prod environment overrides — automatic name prefixing, work pool substitution, and schedule pausing for dev environments.
  • Concurrent deployment application — apply multiple deployments in parallel with clean, non-interleaved log output per deployment.
  • Duplicate deployment name detection — warns (or optionally cleans up) when the same deployment name resolves to more than one flow.

Installation

pip install prefect-deployments-toolkit

Requires Python >= 3.9.

Usage

1. Detect modified deployments

python -m prefect_deployments_toolkit.get_modified_deployments \
  --modified-by push \
  --base-ref main \
  --deployments-dir deployments

Prints a comma-separated list of changed deployment names to stdout, and (if running inside GitHub Actions) writes DEPLOYMENT_NAMES, NEW_OR_MODIFIED_DEPLOYMENT_NAMES, and REMOVED_DEPLOYMENT_NAMES to GITHUB_ENV.

--modified-by accepts:

  • pull_request — compares your local working tree against the fetched base branch (use during an open MR/PR).
  • push or pull_request_target — compares HEAD~1 against HEAD (use after a merge to a protected branch).

2. Apply deployments

python -m prefect_deployments_toolkit \
  --deployment-names "flow_a,flow_b" \
  --enable-schedule false \
  --tag dev \
  --reference feature-branch-1 \
  --repo-name my-flows-repo \
  --custom-image "" \
  --deployments-dir deployments \
  --dev-work-pool my-dev-work-pool \
  --backend rest \
  --enforce-unique-deployment-names false

Expected Repository Layout

deployments/
├── prefect_base.yaml # shared config merged into every deployment
├── flow_a.yaml
├── flow_b.yaml
└── ...

Each deployment YAML file must declare a deployments: list with at least a name and entrypoint key, following the standard Prefect deployment YAML schema.

Backends

Backend How it works When to use
cli Shells out to prefect deploy Simplest, matches local prefect deploy behavior exactly
rest Talks directly to the Prefect REST API Faster for many concurrent deployments, avoids CLI subprocess overhead

Both backends work against Prefect Cloud (api.prefect.cloud) and self-hosted/OSS Prefect servers — the target is determined entirely by PREFECT_API_URL.

Environment Variables

Variable Required Purpose
PREFECT_API_URL Yes Full API base URL. Cloud: https://api.prefect.cloud/api/accounts/<id>/workspaces/<id>. Self-hosted: e.g. https://your-prefect-server.company.com/api
PREFECT_API_KEY Only for Prefect Cloud Cloud API key, sent as a Bearer token
PREFECT_API_AUTH_STRING Only for self-hosted servers with Basic auth enabled Sent as HTTP Basic auth (base64-encoded)

Neither PREFECT_API_KEY nor PREFECT_API_AUTH_STRING is required if your self-hosted Prefect server has no authentication configured — only PREFECT_API_URL is mandatory in every setup.

License

Licensed under PolyForm Noncommercial 1.0.0. You may view, use, and modify this software for noncommercial purposes. Commercial use — including building products, services, or automation on top of it — requires a separate license. Contact kwolski@dyvenia.com for commercial licensing inquiries.

Contributing

Issues and pull requests are welcome for noncommercial use cases. Please open an issue before submitting a large PR to discuss scope.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

prefect_deployments_toolkit-0.1.4.tar.gz (309.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

prefect_deployments_toolkit-0.1.4-py3-none-any.whl (25.4 kB view details)

Uploaded Python 3

File details

Details for the file prefect_deployments_toolkit-0.1.4.tar.gz.

File metadata

File hashes

Hashes for prefect_deployments_toolkit-0.1.4.tar.gz
Algorithm Hash digest
SHA256 78a9bcda53859aae7344e2471e974a294ad05e8ab7d84a2496b91b91b2daa86e
MD5 3948c7810bfc4a435dd56ead194c10bd
BLAKE2b-256 bb1a0833cce53bf32c7a3f0e32e059efd8d90b1450cb3a494ec64bb0f8d86d21

See more details on using hashes here.

Provenance

The following attestation bundles were made for prefect_deployments_toolkit-0.1.4.tar.gz:

Publisher: cd.yml on dyvenia/prefect-deployments-toolkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file prefect_deployments_toolkit-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for prefect_deployments_toolkit-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 d70cbf1807d38361cc2a043b23647b1b9f0abdb2137b25411fcb1f753c9d45f5
MD5 2555af50522a44989455aeffa2fd42d7
BLAKE2b-256 3c61e2687daf56fb4e4902570f05f4f08487e1025fb022872a6ba667d18a4db1

See more details on using hashes here.

Provenance

The following attestation bundles were made for prefect_deployments_toolkit-0.1.4-py3-none-any.whl:

Publisher: cd.yml on dyvenia/prefect-deployments-toolkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.1.5

2 files

This release

0.1.4 This release

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

0.0.9

2 files

0.0.8

2 files

0.0.7

2 files

0.0.6

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page