Skip to main content

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.

manifests:
  - name: other_project
    type: local
    config:
      path: ../other_project/target/manifest.json

datahub:
  enabled: false
  gms_server_env_var: DATAHUB_GMS_SERVER
  token_env_var: DATAHUB_TOKEN

GCS manifest

Install the GCS extra and declare a gcs manifest entry:

pip install 'dbt-prune[gcs]'
manifests:
  - name: analytics
    type: gcs
    config:
      project_id: data-mdm-prod
      bucket_name: tron-dbt-artifacts-prod
      object_name: orchestration/analytics/manifest.json
    excluded_packages:
      - customers
      - customer_platform

Optional GCS config fields:

Field Description
credentials Path to a service-account JSON key file (uses ADC when omitted)
impersonate_service_account Service account email to impersonate

Package filtering

Each manifest entry supports excluded_packages and included_packages (mutually exclusive). Nodes whose package_name is in excluded_packages are dropped from the manifest before orphan evaluation; included_packages keeps only matching nodes.

Optional manifests

Set optional: true on a manifest entry to allow it to fail without aborting the run:

manifests:
  - name: staging
    type: gcs
    optional: true
    config:
      project_id: my-project
      bucket_name: my-bucket
      object_name: staging/manifest.json

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/repo from git remote get-url origin
  • requires GITHUB_TOKEN for 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

Download files

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

Source Distribution

dbt_prune-0.1.1.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

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

dbt_prune-0.1.1-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file dbt_prune-0.1.1.tar.gz.

File metadata

  • Download URL: dbt_prune-0.1.1.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.1

File hashes

Hashes for dbt_prune-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8bcf4d3b09df435454feeef0cc4197575f929b471ed1bbde8f1040effe4bda0c
MD5 fdd7a2cbeb8ebefdc63b4ff003d4e4b4
BLAKE2b-256 ba7ab25b2060259f308e44ea402eb22bd9afb8f4b05198d760044c2ea82229c4

See more details on using hashes here.

File details

Details for the file dbt_prune-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: dbt_prune-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 15.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.1

File hashes

Hashes for dbt_prune-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9ef8c0c0f621754625249e23d8422f93f661ff4dec306b7d859830b939ba30a0
MD5 1835e4a675f6a22a23de606a2b731934
BLAKE2b-256 8351c43ca814e0b3e176fb48ac4b6d34451ebf9c47dc4f7df68efdab0d47e9b8

See more details on using hashes here.

Release history Release notifications | RSS feed

1.3.2

2 files

1.3.1

2 files

1.3.0

2 files

1.2.0

2 files

1.1.0

2 files

1.0.0

2 files

0.5.1

2 files

0.5.0

2 files

0.4.2

2 files

0.4.1

2 files

0.4.0

2 files

0.3.1

2 files

0.3.0

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

This release

0.1.1 This release

2 files

0.1.0

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