Skip to main content

Generate the ERD-as-a-code from dbt artifacts

Project description

dbterd

Generate ERD-as-a-code from your dbt projects

dbterd logo

Transform your dbt artifact files or metadata into stunning Entity Relationship Diagrams using multiple formats: DBML, Mermaid, PlantUML, GraphViz, D2, and DrawDB

docs PyPI version python-cli License: MIT python codecov

dbterd stars

๐Ÿš€ Quick Start

Two ways to get your first ERD on screen โ€” pick whichever matches your mood:

๐Ÿ–ฑ๏ธ Prefer a GUI? Install the dbterd for VS Code extension, open your dbt project, and explore interactive ERDs without touching the command line.

โŒจ๏ธ Prefer the CLI?

pip install dbterd --upgrade
dbterd run -ad samples/dbtresto

That's it โ€” your diagram is generated. Read on for the full tour.

๐ŸŽฏ Entity Relationship Detection

dbterd intelligently detects entity relationships through three algorithms โ€” pick the one that matches how your dbt project expresses its data contracts:

  • ๐Ÿงช Test Relationships (default) โ€” infers relationships from dbt relationships data tests
  • ๐Ÿ›๏ธ Semantic Entities (-a entity_relationship) โ€” detects relationships via dbt Semantic Layer entity definitions
  • ๐Ÿ“œ Model Contract Constraints (-a model_contract) โ€” detects relationships via dbt model contract's foreign_key constraints (dbt 1.9+ / manifest v12+)

For detailed configuration options, see our CLI References.

๐ŸŽจ Supported Output Formats

No need to pick just one โ€” dbterd has a format for every occasion, from quick GitHub previews to full-blown interactive database designers.

Format Description Use Case
DBML Database Markup Language Interactive web diagrams
Mermaid Markdown-friendly diagrams Documentation, GitHub
PlantUML Text-based UML Technical documentation
GraphViz DOT graph description Complex relationship visualization
D2 Modern diagram scripting Beautiful, customizable diagrams
DrawDB Web-based database designer Interactive database design

๐ŸŽฏ Try the Quick Demo with DBML format!

๐ŸŒŸ Ecosystem

dbterd plays well with others. These companion projects build on top of it to take your ERDs beyond the command line:

Project What it does
dbdocs An alternative dbt docs site โ€” catalog, ERD, and column-level lineage baked into a single self-contained HTML file.
dbterd-vscode A VS Code extension that turns your dbt project into interactive ERDs without ever leaving your editor, powered by dbterd under the hood.

๐Ÿš€ Installation

Requires Python 3.10+. dbterd 1.25 was the last release to support Python 3.9; support was dropped since 1.26, as 3.9 reached end-of-life in October 2025 and the dbt 1.11 artifact parser emits X | Y type annotations that won't evaluate on it anyway. If you're still on 3.9, pin dbterd==1.25.* โ€” otherwise upgrade your interpreter (it's worth it).

pip install dbterd --upgrade

Verify Installation:

dbterd --version

[!TIP] For dbt-core users: It's highly recommended to keep artifact-parser updated to the latest version to support newer dbt-core versions and their manifest/catalog json schemas:

pip install "artifact-parser[dbt]" --upgrade

โš™๏ธ Configuration Files

Tired of typing the same CLI arguments repeatedly? Your fingers deserve better. dbterd supports configuration files to streamline your workflow!

# Initialize a configuration file
dbterd init

# Now just run with your saved settings
dbterd run

Supported formats:

  • .dbterd.yml - YAML configuration (recommended)
  • pyproject.toml - Add [tool.dbterd] section to your existing Python project config

Learn more in the Configuration Files Guide.

๐Ÿ’ก Examples

CLI Examples

๐Ÿ–ฑ๏ธ Click to explore CLI examples
# ๐Ÿ“Š Select all models in dbt_resto
dbterd run -ad samples/dbtresto

# ๐ŸŽฏ Select multiple dbt resources (models + sources)
dbterd run -ad samples/dbtresto -rt model -rt source

# ๐Ÿ” Select models excluding staging
dbterd run -ad samples/dbtresto -s model.dbt_resto -ns model.dbt_resto.staging

# ๐Ÿ“‹ Select by schema name
dbterd run -ad samples/dbtresto -s schema:mart -ns model.dbt_resto.staging

# ๐Ÿท๏ธ Select by full schema name
dbterd run -ad samples/dbtresto -s schema:dbt.mart -ns model.dbt_resto.staging

# ๐ŸŒŸ Other sample projects
dbterd run -ad samples/fivetranlog -rt model -rt source
dbterd run -ad samples/facebookad -rt model -rt source
dbterd run -ad samples/shopify -s wildcard:*shopify.shopify__*

# ๐Ÿ”— Custom relationship detection
dbterd run -ad samples/dbt-constraints -a "test_relationship:(name:foreign_key|c_from:fk_column_name|c_to:pk_column_name)"

# ๐Ÿ’ป Your local project
dbterd run -ad samples/local -rt model -rt source

Python API Examples

Generate Complete ERD

from dbterd.api import DbtErd

# Generate DBML format
erd = DbtErd().get_erd()
print("ERD (DBML):", erd)

# Generate Mermaid format
erd = DbtErd(target="mermaid").get_erd()
print("ERD (Mermaid):", erd)

Generate Single Model ERD

from dbterd.api import DbtErd

# Get ERD for specific model
dim_prize_erd = DbtErd(target="mermaid").get_model_erd(
    node_unique_id="model.dbt_resto.dim_prize"
)
print("ERD of dim_prize (Mermaid):", dim_prize_erd)

Sample Output:

erDiagram
  "MODEL.DBT_RESTO.DIM_PRIZE" {
    varchar prize_key
    nvarchar prize_name
    int prize_order
  }
  "MODEL.DBT_RESTO.FACT_RESULT" {
    varchar fact_result_key
    varchar box_key
    varchar prize_key
    date date_key
    int no_of_won
    float prize_value
    float prize_paid
    int is_prize_taken
  }
  "MODEL.DBT_RESTO.FACT_RESULT" }|--|| "MODEL.DBT_RESTO.DIM_PRIZE": prize_key

๐Ÿค Contributing

We welcome contributions! Whether you've found a bug, dreamed up a feature, or just want to fix a typo โ€” you're very welcome here.

Ways to contribute: ๐Ÿ› Report bugs | ๐Ÿ’ก Suggest features | ๐Ÿ“ Improve documentation | ๐Ÿ”ง Submit pull requests

See our Contributing Guide for detailed information.

Show your support:

  • โญ Star this repository
  • ๐Ÿ“ข Share on social media
  • โœ๏ธ Write a blog post
  • โ˜• Buy me a coffee

buy me a coffee

๐Ÿ‘ฅ Contributors

A huge thanks to our amazing contributors โ€” the people who turned "wouldn't it be nice if..." into actual working code. ๐Ÿ™

๐Ÿ“ง Support

Need help? We're here for you! Check ๐Ÿ“– Documentation, ๐Ÿ› Report Issues and ๐Ÿ’ฌ Discussions

Star History Chart

Made with โค๏ธ by the dbterd community


Sponsored by GitAds

Sponsored by GitAds

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

dbterd-1.27.0.tar.gz (61.3 kB view details)

Uploaded Source

Built Distribution

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

dbterd-1.27.0-py3-none-any.whl (79.6 kB view details)

Uploaded Python 3

File details

Details for the file dbterd-1.27.0.tar.gz.

File metadata

  • Download URL: dbterd-1.27.0.tar.gz
  • Upload date:
  • Size: 61.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for dbterd-1.27.0.tar.gz
Algorithm Hash digest
SHA256 3b534058b19b2a52de0e97b1f45f345599b407c177cffdcb274f1f6d4a939648
MD5 60c7a3eb0d5ac67e75906ced18003a7b
BLAKE2b-256 14fd768e87ffa0ce76329afc356421fae62361b5a921233928d25eb0f947eaeb

See more details on using hashes here.

Provenance

The following attestation bundles were made for dbterd-1.27.0.tar.gz:

Publisher: pypi-publish.yml on datnguye/dbterd

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

File details

Details for the file dbterd-1.27.0-py3-none-any.whl.

File metadata

  • Download URL: dbterd-1.27.0-py3-none-any.whl
  • Upload date:
  • Size: 79.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for dbterd-1.27.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5a3a5aae3f323eea451b68dc93a0f3d55fc0a2864e5e240df10e4f5007128ddb
MD5 89d0d424f1f2d510b0c0b3ffd583f48d
BLAKE2b-256 e0b2f52d920e65947589f6967b1e8fce2d7e2b96ad71a14ded0c602d7299aa17

See more details on using hashes here.

Provenance

The following attestation bundles were made for dbterd-1.27.0-py3-none-any.whl:

Publisher: pypi-publish.yml on datnguye/dbterd

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

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page