Find orphaned dbt models and snapshots across multiple manifests and open Copilot-powered cleanup tasks.
Project description
dbt-prune
dbt-prune is a pip-installable dbt-core companion CLI for finding dbt models and snapshots that are no longer referenced by anything in your current project, configured sibling projects, or dbt exposures.
Installation
pip install dbt-prune
Optional integrations stay lightweight by default:
pip install 'dbt-prune[gcs]'
pip install 'dbt-prune[datahub]'
Configuration
By default dbt-prune looks for dbt_prune.config.yml in the dbt project root passed to --project-dir.
projects:
- name: other_project
manifest:
type: local
path: ../other_project/target/manifest.json
datahub:
enabled: false
gms_server_env_var: DATAHUB_GMS_SERVER
token_env_var: DATAHUB_TOKEN
Important DataHub note
The config file stores the names of the environment variables only. The actual DataHub GMS server URL and token must come from the environment at runtime:
export DATAHUB_GMS_SERVER=https://datahub.example.com
export DATAHUB_TOKEN=...
How orphan detection works
dbt-prune only parses manifest.json files. It does not run dbt, compile models, or introspect a live warehouse.
It loads:
- the current project's
target/manifest.json - any configured external manifests from local paths or
gs://URIs - exposure dependencies from every loaded manifest
A current-project model or snapshot is considered orphaned only when it has zero incoming references from any loaded manifest and is not referenced by any exposure. If DataHub checking is enabled, downstream lineage consumers also keep a node off the orphan list.
Usage
List all orphaned assets
dbt-prune ls --project-dir .
Inspect one specific model
dbt-prune ls --project-dir . -s my_model
When -s/--select is used, dbt-prune reports whether the named model or snapshot is orphaned and explains why.
JSON output
dbt-prune ls --format json
Open Copilot cleanup tasks for every orphan
dbt-prune run --project-dir .
Behavior:
- scans all current-project models and snapshots by default
- opens one GitHub Copilot coding-agent task per orphan
- auto-detects the target
owner/repofromgit remote get-url origin - requires
GITHUB_TOKENfor GitHub API authentication
Dry-run the cleanup plan
dbt-prune run --dry-run
Restrict cleanup to one model
dbt-prune run -s my_model
Limit the number of cleanup tasks
dbt-prune run --limit 5
DataHub integration
When datahub.enabled: true, dbt-prune queries DataHub for downstream lineage before marking an otherwise unreferenced asset as orphaned.
If the required environment variables are missing or DataHub is unreachable, dbt-prune warns and continues unless you pass --strict.
GitHub Copilot coding-agent PR automation
dbt-prune run generates a clear problem statement for each orphaned asset and sends it to GitHub through dbt_prune.pr_agent. The default implementation creates a GitHub issue payload intended for Copilot coding-agent workflows, and the module is designed to be replaceable if your organization uses a dedicated Copilot task/session endpoint.
Development
python -m pip install -e '.[dev]'
ruff check .
pytest
mypy dbt_prune
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dbt_prune-0.1.0.tar.gz.
File metadata
- Download URL: dbt_prune-0.1.0.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cd30e692da34ede39c2ca80f9d15429f6e6299d23a2f27e39bcd09bf84fd3f57
|
|
| MD5 |
0f5357fdd471ee7680d6972245f15556
|
|
| BLAKE2b-256 |
8e4664ce86f5217d65479d33ca6a6b7f27e91f718d48867addc4711c413f2bb7
|
File details
Details for the file dbt_prune-0.1.0-py3-none-any.whl.
File metadata
- Download URL: dbt_prune-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4468fa3f8e967e510b840b9f5ef99a860a2fa19dc7511c3d1eba58ac301f2edf
|
|
| MD5 |
6f4d8d630e5b84b9cc8905a560156fc4
|
|
| BLAKE2b-256 |
63348f121c2bdfdf321e1f87298bd81ce9a33c4408e7830c5c107212162acd84
|