# dbterd
Generate the ERD-as-a-code ([DBML](https://dbdiagram.io/d), [Mermaid](https://mermaid-js.github.io/mermaid-live-editor/), [PlantUML](https://plantuml.com/ie-diagram), [GraphViz](https://graphviz.org/), [D2](https://d2lang.com/)) from dbt artifact files (`dbt Core`) or from dbt metadata (`dbt Cloud`)
[![PyPI version](https://badge.fury.io/py/dbterd.svg)](https://pypi.org/project/dbterd/)
![python-cli](https://img.shields.io/badge/CLI-Python-FFCE3E?labelColor=14354C&logo=python&logoColor=white)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![python](https://img.shields.io/badge/Python-3.9|3.10|3.11-3776AB.svg?style=flat&logo=python&logoColor=white)](https://www.python.org)
[![codecov](https://codecov.io/gh/datnguye/dbterd/branch/main/graph/badge.svg?token=N7DMQBLH4P)](https://codecov.io/gh/datnguye/dbterd)
```bash
pip install dbterd --upgrade
```
Verify installation:
```bash
dbterd --version
```
> [!TIP]
> For `dbt-core` Users, it's highly recommended to upgrade `dbt-artifacts-parser` to the latest version in order to support the newer `dbt-core` version which would cause to have the [new manifest / catalog json schema](https://schemas.getdbt.com/):</br>
> π `pip install dbt-artifacts-parser --upgrade`
## Quick examine with existing samples
- Play with CLIs:
<details>
<summary>Click me</summary>
```bash
# 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
```
</details>
- Play with Python API (whole ERD):
```python
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):
```python
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_prize (mermaid):", dim_prize_erd)
```
Here is the output:
```mermaid
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
```
</details>
πCheck out the [Quick Demo](https://dbterd.datnguyen.de/latest/nav/guide/targets/generate-dbml.html) with DBML!
## Contributing β¨
If you've ever wanted to contribute to this tool, and a great cause, now is your chance!
See the contributing docs [CONTRIBUTING](https://dbterd.datnguyen.de/latest/nav/development/contributing-guide.html) for more information.
If you've found this tool to be very helpful, please consider giving the repository a star, sharing it on social media, or even writing a blog post about it π
[![dbterd stars](https://img.shields.io/github/stars/datnguye/dbterd.svg?logo=github&style=for-the-badge&label=Star%20this%20repo)](https://github.com/datnguye/dbterd)
[![buy me a coffee](https://img.shields.io/badge/buy%20me%20a%20coffee-donate-yellow.svg?logo=buy-me-a-coffee&logoColor=white&labelColor=ff813f&style=for-the-badge)](https://www.buymeacoffee.com/datnguye)
Finally, super thanks to our *Contributors*:
<a href="https://github.com/datnguye/dbterd/graphs/contributors">
<img src="https://contrib.rocks/image?repo=datnguye/dbterd" />
</a>
</br>
Raw data
{
"_id": null,
"home_page": "https://github.com/datnguye/dbterd",
"name": "dbterd",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.9",
"maintainer_email": null,
"keywords": "flake8, markdown, lint",
"author": "Dat Nguyen",
"author_email": "datnguyen.it09@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/ba/53/09bae01f2368afc594e6deb9bf4a014311cb05a23b26e450dc9b60e5c514/dbterd-1.13.3.tar.gz",
"platform": null,
"description": "# dbterd\n\nGenerate the ERD-as-a-code ([DBML](https://dbdiagram.io/d), [Mermaid](https://mermaid-js.github.io/mermaid-live-editor/), [PlantUML](https://plantuml.com/ie-diagram), [GraphViz](https://graphviz.org/), [D2](https://d2lang.com/)) from dbt artifact files (`dbt Core`) or from dbt metadata (`dbt Cloud`)\n\n[![PyPI version](https://badge.fury.io/py/dbterd.svg)](https://pypi.org/project/dbterd/)\n![python-cli](https://img.shields.io/badge/CLI-Python-FFCE3E?labelColor=14354C&logo=python&logoColor=white)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![python](https://img.shields.io/badge/Python-3.9|3.10|3.11-3776AB.svg?style=flat&logo=python&logoColor=white)](https://www.python.org)\n[![codecov](https://codecov.io/gh/datnguye/dbterd/branch/main/graph/badge.svg?token=N7DMQBLH4P)](https://codecov.io/gh/datnguye/dbterd)\n\n```bash\npip install dbterd --upgrade\n```\n\nVerify installation:\n\n```bash\ndbterd --version\n```\n\n> [!TIP]\n> For `dbt-core` Users, it's highly recommended to upgrade `dbt-artifacts-parser` to the latest version in order to support the newer `dbt-core` version which would cause to have the [new manifest / catalog json schema](https://schemas.getdbt.com/):</br>\n> \ud83d\udc49 `pip install dbt-artifacts-parser --upgrade`\n\n## Quick examine with existing samples\n\n- Play with CLIs:\n\n <details>\n <summary>Click me</summary>\n\n ```bash\n # select all models in dbt_resto\n dbterd run -ad samples/dbtresto\n # select all models in dbt_resto, Select multiple dbt resources\n dbterd run -ad samples/dbtresto -rt model -rt source\n # select only models in dbt_resto excluding staging\n dbterd run -ad samples/dbtresto -s model.dbt_resto -ns model.dbt_resto.staging\n # select only models in schema name mart excluding staging\n dbterd run -ad samples/dbtresto -s schema:mart -ns model.dbt_resto.staging\n # select only models in schema full name dbt.mart excluding staging\n dbterd run -ad samples/dbtresto -s schema:dbt.mart -ns model.dbt_resto.staging\n\n # other samples\n dbterd run -ad samples/fivetranlog\n dbterd run -ad samples/fivetranlog -rt model -rt source\n\n dbterd run -ad samples/facebookad\n dbterd run -ad samples/facebookad -rt model -rt source\n\n dbterd run -ad samples/shopify -s wildcard:*shopify.shopify__*\n dbterd run -ad samples/shopify -rt model -rt source\n\n dbterd run -ad samples/dbt-constraints -a \"test_relationship:(name:foreign_key|c_from:fk_column_name|c_to:pk_column_name)\"\n\n # your own sample without commiting to repo\n dbterd run -ad samples/local -rt model -rt source\n ```\n\n </details>\n\n- Play with Python API (whole ERD):\n\n ```python\n from dbterd.api import DbtErd\n\n erd = DbtErd().get_erd()\n print(\"erd (dbml):\", erd)\n\n erd = DbtErd(target=\"mermaid\").get_erd()\n print(\"erd (mermaid):\", erd)\n ```\n\n- Play with Python API (1 model's ERD):\n\n ```python\n from dbterd.api import DbtErd\n\n dim_prize_erd = DbtErd(target=\"mermaid\").get_model_erd(\n node_unique_id=\"model.dbt_resto.dim_prize\"\n )\n print(\"erd of dim_prize (mermaid):\", dim_prize_erd)\n ```\n\n Here is the output:\n\n ```mermaid\n erDiagram\n \"MODEL.DBT_RESTO.DIM_PRIZE\" {\n varchar prize_key\n nvarchar prize_name\n int prize_order\n }\n \"MODEL.DBT_RESTO.FACT_RESULT\" {\n varchar fact_result_key\n varchar box_key\n varchar prize_key\n date date_key\n int no_of_won\n float prize_value\n float prize_paid\n int is_prize_taken\n }\n \"MODEL.DBT_RESTO.FACT_RESULT\" }|--|| \"MODEL.DBT_RESTO.DIM_PRIZE\": prize_key\n ```\n\n</details>\n\n\ud83c\udfc3Check out the [Quick Demo](https://dbterd.datnguyen.de/latest/nav/guide/targets/generate-dbml.html) with DBML!\n\n## Contributing \u2728\n\nIf you've ever wanted to contribute to this tool, and a great cause, now is your chance!\n\nSee the contributing docs [CONTRIBUTING](https://dbterd.datnguyen.de/latest/nav/development/contributing-guide.html) for more information.\n\nIf you've found this tool to be very helpful, please consider giving the repository a star, sharing it on social media, or even writing a blog post about it \ud83d\udc8c\n\n[![dbterd stars](https://img.shields.io/github/stars/datnguye/dbterd.svg?logo=github&style=for-the-badge&label=Star%20this%20repo)](https://github.com/datnguye/dbterd)\n[![buy me a coffee](https://img.shields.io/badge/buy%20me%20a%20coffee-donate-yellow.svg?logo=buy-me-a-coffee&logoColor=white&labelColor=ff813f&style=for-the-badge)](https://www.buymeacoffee.com/datnguye)\n\nFinally, super thanks to our *Contributors*:\n\n<a href=\"https://github.com/datnguye/dbterd/graphs/contributors\">\n <img src=\"https://contrib.rocks/image?repo=datnguye/dbterd\" />\n</a>\n\n</br>\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Generate the ERD-as-a-code from dbt artifacts",
"version": "1.13.3",
"project_urls": {
"Homepage": "https://github.com/datnguye/dbterd",
"Repository": "https://github.com/datnguye/dbterd"
},
"split_keywords": [
"flake8",
" markdown",
" lint"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "39b8a2ae4726f135b2989388911903d3797e9b5d25c38a34b2391c4f5be63bc2",
"md5": "f4b3576574634480bd82573503b28f7b",
"sha256": "0f5c0dec84d7149e6ada6d19a66a0bd13f62edb7439776c2cc3fbabd6092bfda"
},
"downloads": -1,
"filename": "dbterd-1.13.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "f4b3576574634480bd82573503b28f7b",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 42580,
"upload_time": "2024-05-03T05:42:56",
"upload_time_iso_8601": "2024-05-03T05:42:56.558219Z",
"url": "https://files.pythonhosted.org/packages/39/b8/a2ae4726f135b2989388911903d3797e9b5d25c38a34b2391c4f5be63bc2/dbterd-1.13.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "ba5309bae01f2368afc594e6deb9bf4a014311cb05a23b26e450dc9b60e5c514",
"md5": "f2e7eefeee4f341def00910256e30dc4",
"sha256": "be0769f784953bfd6380d8589e1664748b38068d79964845b2e837313c6a263e"
},
"downloads": -1,
"filename": "dbterd-1.13.3.tar.gz",
"has_sig": false,
"md5_digest": "f2e7eefeee4f341def00910256e30dc4",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 30298,
"upload_time": "2024-05-03T05:42:58",
"upload_time_iso_8601": "2024-05-03T05:42:58.790065Z",
"url": "https://files.pythonhosted.org/packages/ba/53/09bae01f2368afc594e6deb9bf4a014311cb05a23b26e450dc9b60e5c514/dbterd-1.13.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-03 05:42:58",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "datnguye",
"github_project": "dbterd",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "dbterd"
}