{"id":23886131,"url":"https://github.com/dpguthrie/dbt-dynamic-models","last_synced_at":"2026-06-22T05:32:15.960Z","repository":{"id":102289890,"uuid":"523485442","full_name":"dpguthrie/dbt-dynamic-models","owner":"dpguthrie","description":"Generate dbt models dynamically from config","archived":false,"fork":false,"pushed_at":"2022-09-29T16:22:12.000Z","size":87,"stargazers_count":1,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-23T03:28:54.907Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dpguthrie.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-08-10T20:19:33.000Z","updated_at":"2025-01-07T18:59:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"670b9ab7-b929-4fc2-8bc9-6c4daa6741e6","html_url":"https://github.com/dpguthrie/dbt-dynamic-models","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/dpguthrie/dbt-dynamic-models","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpguthrie%2Fdbt-dynamic-models","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpguthrie%2Fdbt-dynamic-models/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpguthrie%2Fdbt-dynamic-models/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpguthrie%2Fdbt-dynamic-models/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dpguthrie","download_url":"https://codeload.github.com/dpguthrie/dbt-dynamic-models/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpguthrie%2Fdbt-dynamic-models/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34636427,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-22T02:00:06.391Z","response_time":106,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-04T05:56:51.987Z","updated_at":"2026-06-22T05:32:15.949Z","avatar_url":"https://github.com/dpguthrie.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Dynamic Models\n\nGenerate dbt models dynamically from config!\n\nThis package is useful if you have the same SQL query that you need parameterized to create 1 -\u003e N number of models.  The benefit of this approach is that we still get to leverage the best of dbt:  using `ref`s and `source`s, testing, and documentation!\n\n## Overview\n\nWatch a quick loom video!  https://www.loom.com/share/c60b996e408d4534ad048a9308781ff1\n\nThis is a simple CLI tool that allows a user to dynamically create models within your dbt project.\n\n## Requirements\n\nPython 3.7+\n\n- Typer - Library for building CLI applications\n- PyYAML - Fully-featured YAML framework for python\n\n## Installation\n\n`pip install dbt-dynamic-models`\n\n## Basic Usage\n\nThe CLI can be accessed with `dbtgen` and there are two commands available:\n\n- `models` - Dynamically generate models\n- `profile` - Create the yml to be inserted into your profiles.yml file\n\nThe `models` command is keyed off a specific config inside a yml file in your dbt_project\n\n### config\n\nInside 1 or more yml files within your models directory, you'll include the following top-level key:\n\n```yml\ndynamic_models:\n```\n\nWithin the top-level `dynamic_models` key, you'll need the following required arguments:\n- `name` - This is the name of the model dbt will create\n- `location` - This is where dbt will create the model file\n- `params` - This is what we'll use to parameterize our SQL\n- `sql` - This is the SQL that will be included within each file\n\nHere's an example of what that looks like:\n\n```yml\ndynamic_models:\n  - name: '{customer}_{model}'\n    location: customers/{customer}/\n    params:\n      - name: customer\n        query: |\n          select lower(schema_name) as customer\n          from doug_demo.information_schema.schemata\n          where schema_name like 'CUST_%'\n      - name: model\n        values:\n          - dim_customers\n          - dim_parts\n          - dim_suppliers\n          - fct_order_items\n          - fct_orders\n    sql: |\n      {{{{ config(schema='{customer}', alias='{model}') }}}}\n\n      select {{{{ dbt_utils.star(ref('{model}'), except=['customer']) }}}}\n      from {{{{ ref('{model}') }}}}\n      where customer = '{customer}'\n```\n\nA few things you should notice from the code above:\n\n- The placeholders within each string for name, location, and sql are being derived from the name of the parameters themselves.  **You can see we're also able to use SQL to parameterize our models!**\n- We have parameterized our model name - dbt expects each model name to be unique\n- Slight inconvenience - our jinja has to be escaped so python doesn't look for it as a placeholder.  For instance, `{{ ref('some_model') }}` becomes `{{{{ ref('some_model') }}}}` because we use a curly brace to escape a curly brace we want to exist within our string.\n- **All placeholders are lowercase**\n\n### dbt-Core\n\nTo run this locally, simply `pip install dbt-dynamic-models` alongside your project, create your `dynamic_models` config, and then run this command:\n\n```bash\ndbtgen models\n```\n\n*This assumes that your profiles.yml file is located at `~/.dbt`*\n\n### dbt Cloud\n\nCurrently, this can only be run via a github action, or the similar verbiage for different git providers.  An example action is located [here](/.github/workflows/test.yml)\n\nAt a high-level, the action does the following:\n\n- Checkout your repo\n- Install python\n- Install dependencies - `pip install dbt-dynamic-models[snowflake]`.\n- Generate a profiles.yml file\n- Generate models\n\n## To-Do\n\nAllow for dynamic creation of yml files for models created - tests, descriptions, etc.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdpguthrie%2Fdbt-dynamic-models","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdpguthrie%2Fdbt-dynamic-models","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdpguthrie%2Fdbt-dynamic-models/lists"}