Skip to main content

Tool to generate dbt resources.

Project description

dbt-gen

Tool for generating dbt model, source files.

Commands

1. Generate dbt project from cookiecutter template

dbt_gen generate_dbt

2. Generate source

dbt_gen generate_source --help

usage: dbt_gen generate_source [-h] [--profile-path PROFILE_PATH]
                               [--profile-name PROFILE_NAME] [--target TARGET]
                               [--database DATABASE] [--threads THREADS]
                               source_folder

positional arguments:
  source_folder         Folder to write source YAML files

optional arguments:
  -h, --help            show this help message and exit
  --profile-path PROFILE_PATH
                        Path to dbt profile YAML. Default is
                        /home/tien/.dbt/profiles.yml
  --profile-name PROFILE_NAME
                        Dbt profile name. Default is `default`.
  --target TARGET       Dbt profile target. Default is `dev`.
  --database DATABASE   Database to inspect. Default is the database in
                        profile.
  --threads THREADS     Max threads. Default is your machine number of
                        threads.

3. Generate base models and tests

dbt_gen generate_base_model --help

usage: dbt-gen generate_base_model [-h] [--profile-path PROFILE_PATH]
                                   [--profile-name PROFILE_NAME]
                                   [--target TARGET] [--threads THREADS]
                                   [--template TEMPLATE]
                                   source_path output_folder

positional arguments:
  source_path           Path to dbt source YAML.
  output_folder         Folder to write base models.

optional arguments:
  -h, --help            show this help message and exit
  --profile-path PROFILE_PATH
                        Path to dbt profile YAML. Default is
                        /home/tien/.dbt/profiles.yml
  --profile-name PROFILE_NAME
                        Dbt profile name. Default is `default`.
  --target TARGET       Dbt profile target. Default is `dev`.
  --threads THREADS     Max threads. Default is your machine number of
                        threads.
  --template TEMPLATE   Path to custom Jinja template.

3.1 Generate base models using custom Jinja template

  • Get default Jinja template by running
dbt-gen get_template > your_custom_template.sql
  • Edit your custom template
  • Run generating base models using the custom template
dbt-gen generate_base_models --template your_custom_template.sql path/to/source path/to/output

3.2. Jinja variables in rendering base models

  • source_name
    • Type: String
  • table_name
    • Type: String
  • columns
    • Type: Array of objects
    • Item:
      • Type: object
      • Attributes:
        • database: String
        • schema: String
        • table: String
        • name: String
        • position: Integer
        • nullable: Boolean
        • dtype: String
        • extra: Dict

4. Generate base tests

dbt_gen generate_base_test --help

usage: dbt-gen generate_base_test [-h] [--profile-path PROFILE_PATH]
                                  [--profile-name PROFILE_NAME]
                                  [--target TARGET]
                                  source_path output_folder

positional arguments:
  source_path           Path to dbt source YAML.
  output_folder         Folder to write base models.

optional arguments:
  -h, --help            show this help message and exit
  --profile-path PROFILE_PATH
                        Path to dbt profile YAML. Default is
                        /home/tien/.dbt/profiles.yml
  --profile-name PROFILE_NAME
                        Dbt profile name. Default is `default`.
  --target TARGET       Dbt profile target. Default is `dev`.

Caveats

  • For BigQuery sources, dbt-gen supports making tests only based on Stitch meta table _sdc_primary_keys. If there is no such table, test YAML will be empty.
  • For Snowflake, dbt-gen makes tests based on Snowflake table constraints.

TODOs

  • Add primary keys information into variables in rendering base model SQLs

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dbt_gen-0.1.7.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

dbt_gen-0.1.7-py3-none-any.whl (26.6 kB view details)

Uploaded Python 3

File details

Details for the file dbt_gen-0.1.7.tar.gz.

File metadata

  • Download URL: dbt_gen-0.1.7.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.2.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.12

File hashes

Hashes for dbt_gen-0.1.7.tar.gz
Algorithm Hash digest
SHA256 f3d874caaf958e2a0baac9edd599088e7f6b397ef9186cabd7453c3ee62f9c36
MD5 b288df277cbca56191403f41e0cfa3f5
BLAKE2b-256 6eb193a555488fbe626e5d613d8247c1cdb20e7a801583fe6dd519afcf0dd39d

See more details on using hashes here.

File details

Details for the file dbt_gen-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: dbt_gen-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 26.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.2.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.12

File hashes

Hashes for dbt_gen-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 2c49a635f7f074bd10469921f10ef3ab09e3c14f5c915012206c75cdd1759946
MD5 ceb509b41cfe916ea119cb954e0b702e
BLAKE2b-256 4ff249856170652721e7b53c1c1310cda9a5d05fabf7c31096e4839cc4b53478

See more details on using hashes here.

Supported by

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