Skip to main content

dbt-prune

dbt-prune is a pip-installable dbt-core companion CLI for finding dbt models, snapshots, and sources 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]'

Checking the installed version

dbt-prune --version

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
  platform: bigquery
  env: PROD

whitelist:
  - my_model
  - important_snapshot

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.

Whitelisting models

Use the top-level whitelist to keep specific current-project models or snapshots from ever being reported as orphaned. Whitelisted assets never appear in dbt-prune ls output and are skipped by dbt-prune run:

whitelist:
  - my_model
  - important_snapshot

Entries are matched against the node name. When you inspect a whitelisted asset directly with -s/--select, dbt-prune reports it as not orphaned with the reason Whitelisted in dbt_prune.config.yml.

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, snapshot, or source is considered orphaned only when it has zero incoming references from any loaded manifest and is not referenced by any exposure. An unused source is one that no model in any loaded manifest selects via source(). 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 .

By default ls reports orphaned models, snapshots, and unused sources.

Filter by resource type

Restrict the listing to a single resource type with --resource-type (model, snapshot, or source):

dbt-prune ls --resource-type source

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.

Filter by package

Scope orphan detection to a specific dbt package within your project using -p/--package:

dbt-prune ls -p marketing_core

Combine with -s/--select to inspect a specific model within a package:

dbt-prune ls -p marketing_core -s some_model_name

The same flag works for run:

dbt-prune run -p marketing_core --dry-run

JSON output

dbt-prune ls --format json

Start a Copilot agent session to delete every orphan

dbt-prune run --project-dir .

Behavior:

  • scans all current-project models and snapshots by default
  • builds a single prompt listing every orphaned asset
  • starts one agent session via gh agent-task create "PROMPT"
  • the prompt instructs the agent to delete the model files and every properties.yml / schema.yml reference to them, then open a pull request
  • requires the GitHub CLI (gh) to be installed and authenticated

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 assets in the prompt

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.

Dataset URNs are built from each manifest node's materialized location: database.schema.alias (falling back to name when alias is omitted). Ensure the manifest's database / schema / alias values match how your warehouse assets are ingested into DataHub.

Use datahub.platform and datahub.env to match your DataHub dataset URN convention:

datahub:
  enabled: true
  gms_server_env_var: DATAHUB_GMS_SERVER
  token_env_var: DATAHUB_TOKEN
  platform: bigquery
  env: PROD
  extra_platforms: [dbt]   # also probed when the warehouse URN has no lineage

Lineage is resolved with a searchAcrossLineage GraphQL query in the DOWNSTREAM direction. Because dbt-managed assets are often ingested under both the warehouse platform and the dbt platform (as siblings), each URN in platform + extra_platforms is probed and the asset is kept if any of them reports downstreams. Set extra_platforms: [] to probe only the warehouse platform.

GraphQL errors returned by DataHub are surfaced as warnings (or raised with --strict) rather than being treated as "no downstreams".

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 builds a single cleanup prompt covering every orphaned asset in dbt_prune.pr_agent and starts a Copilot coding-agent session with gh agent-task create. The module also still exposes a REST-based issue creator (GitHubCopilotPRAgent) for teams that prefer issue-driven workflows.

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.2.2.tar.gz (20.2 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.2.2-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dbt_prune-0.2.2.tar.gz
  • Upload date:
  • Size: 20.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for dbt_prune-0.2.2.tar.gz
Algorithm Hash digest
SHA256 c48f0c79410937c4ab89a8342f3becd98321b6a243b1e9925caf076084da24a9
MD5 1690810dd1e1dabe26dde02aba20ec2c
BLAKE2b-256 6dc12a9b393f03a9ae0f8f3b3d9115e08ee41c49089c541bc90b345a2a95bd79

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dbt_prune-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 18.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for dbt_prune-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c06e577f8fd51d890fc8cfe2a5350aff8d1368624d2683ce37b3aa687eee7b0c
MD5 0ad9fb8981dbc4e653c44d5fbdebb528
BLAKE2b-256 d8f62825342d1c235f34ffdd46e9e46584aee2932f980e5da82ed629e20c1a36

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

This release

0.2.2 This release

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

0.1.1

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