Skip to content

datnguye/dbterd

dbterd

CLI to generate Diagram-as-a-code file (DBML, Mermaid, PlantUML, GraphViz, D2) from dbt artifact files (required: dbt dbt)

PyPI version python-cli License: MIT python codecov

pip install dbterd --upgrade

Verify installation:

dbterd --version

Quick examine with existing samples

Play with CLI
# select all models in dbt_resto
dbterd run -ad samples/dbtresto
# select all models in dbt_resto, Select multiple dbt resources
dbterd run -ad samples/dbtresto -rt model -rt source
# select only models in dbt_resto excluding staging
dbterd run -ad samples/dbtresto -s model.dbt_resto -ns model.dbt_resto.staging
# select only models in schema name mart excluding staging
dbterd run -ad samples/dbtresto -s schema:mart -ns model.dbt_resto.staging
# select only models in schema full name dbt.mart excluding staging
dbterd run -ad samples/dbtresto -s schema:dbt.mart -ns model.dbt_resto.staging

# other samples
dbterd run -ad samples/fivetranlog
dbterd run -ad samples/fivetranlog -rt model -rt source

dbterd run -ad samples/facebookad
dbterd run -ad samples/facebookad -rt model -rt source

dbterd run -ad samples/shopify -s wildcard:*shopify.shopify__*
dbterd run -ad samples/shopify -rt model -rt source

dbterd run -ad samples/dbt-constraints -a "test_relationship:(name:foreign_key|c_from:fk_column_name|c_to:pk_column_name)"

# your own sample without commiting to repo
dbterd run -ad samples/local -rt model -rt source
Play with Python API (whole ERD)
from dbterd.api import DbtErd

erd = DbtErd().get_erd()
print("erd (dbml):", erd)

erd = DbtErd(target="mermaid").get_erd()
print("erd (mermaid):", erd)
Play with Python API (1 model's ERD)
from dbterd.api import DbtErd

dim_prize_erd = DbtErd(target="mermaid").get_model_erd(
    node_unique_id="model.dbt_resto.dim_prize"
)
print("erd of dim_date (mermaid):", dim_prize_erd)

Here is the output:

Loading
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

Quick DEMO

Check Quick Demo out! And, following is the sample result using dbdocs:

screencapture-dbdocs-io-datnguye-poc-2023-02-25-10_29_32.png

Contributing ✨

If you've ever wanted to contribute to this tool, and a great cause, now is your chance!

See the contributing docs CONTRIBUTING for more information.

Finally, super thanks to our Contributors: