Skip to main content

dbt-generator

This package helps in generating the base models and transform them in bulk. For sources with 10+ models, this package will save you a lot of time by generating base models in bulk and transform them for common fields. Using this package is a great way to start your modeling or onboarding new sources.

Installation

To use this package, you need dbt installed with a profile configured. You will also need to install the code-gen package from dbt Hub. Add the following to the packages.yml file in your dbt repo and run dbt deps to install dependencies.

packages:
  - package: dbt-labs/codegen
    version: 0.4.0

Install the package in the same environment with your dbt installation by running:

pip install dbt-generator

This package should be executed inside your dbt repo.

Generate base models

To generate base models, use the dbt-generator generate command. This is a wrapper around the codegen command that will generate the base models. This is especially useful when you have a lot of models, and you want to generate them all at once.

Usage: dbt-generator generate [OPTIONS]

  Gennerate base models based on a .yml source

Options:
  -s, --source-yml PATH   Source .yml file to be used
  -o, --output-path PATH  Path to write generated models
  -m, --model STRING      Model name
  -c, --custom_prefix.    Enter a Custom String Prefix for Model Filename
  --model-prefix BOOLEAN  optional prefix of source_name + "_" to the resulting modelname.sql to avoid model name collisions across sources 
  --source-index INTEGER  Index of the source to generate base models for
  --help                  Show this message and exit.

Example

dbt-generator generate -s ./models/source.yml -o ./models/staging/source_name/

This will read in the source.yml file and generate the base models in the staging/source_name folder. If you have multiple sources defined in your yml file, use the --source-index flag to specify which source you want to generate base models for.

Transform base models using a custom YAML file

For the same source, you often have consistent naming conventions between tables. For example, the created_at and modified_at fields are often named the same for all tables. Changing all these fields to common values across different sources is a best practice. However, doing that for all the date columns in 10+ tables is a pain.

With this package, you can write a transforms.yml file that will be read in (the .yml file can be named anything). This file will contain the transforms that you want to apply to all the base models. You can just rename the fields in the base models or apply a custom SQL select to the transformed fields.

Usage: dbt-generator transform [OPTIONS]

  Transform base models in a directory using a transforms.yml file

Options:
  -m, --model-path PATH       The path to models
  -t, --transforms-path PATH  Path to a .yml file containing transformations
  -o, --output-path PATH      Path to write transformed models to
  --drop-metadata BOOLEAN     (default=False) optionally drop source columns prefixed with "_" if that designates metadata columns not needed in target
  --case-sensitive BOOLEAN    (default=False) treat column names as case-sensitive - otherwise force all to lower
  --help                      Show this message and exit.

Transform base models using pre-built configs

Supported data warehouse:

  • BigQuery: bq_transform
  • Snowflake: sf_transform
Usage: dbt-generator bq-transform/sf-transform [OPTIONS]

  Transform base models in a directory for BigQuery source

Options:
  -m, --model-path PATH        The path to models
  -o, --output-path PATH       Path to write transformed models to
  --drop-metadata BOOLEAN      (default=False) optionally drop source columns prefixed with "_" if that designates metadata columns not needed in target
  --case-sensitive BOOLEAN     (default=False) treat column names as case-sensitive - otherwise force all to lower
  --split-columns BOOLEAN      Split column names. E.g. currencycode =>
                               currency_code
  --id-as-int BOOLEAN          Convert id to int
  --convert-timestamp BOOLEAN  Convert timestamp to datetime
  --help                       Show this message and exit.

Example

ID:
  name: ID
  sql: CAST(ID as INT64)
CREATED_TIME:
  name: CREATED_AT
UPDATED_TIME:
  name: MODIFIED_AT
DATE_START:
  name: START_AT
DATE_STOP:
  name: STOP_AT

This .yml file when applied to all models in the staging/source_name folder will cast all ID field to INT64 and rename all the date columns to a value in the name key. For example, CREATED_TIME will be renamed to CREATED_AT and DATE_START will be renamed to START_AT. If no sql is provided, the package will just rename the field. If a sql is provided, the package will execute the SQL and rename the field using the name key.

dbt-generator transform -m ./models/staging/source_name/ -t ./transforms.yml

This will transform all models in the staging/source_name folder using the transforms.yml file. You can also drop the metadata by setting the drop-metadata flag to true (dropping columns start with _). The --case-sensitive flag will determine if the transforms will use case-sensitive names or not.

Limitations

Here are some of the limitations of the current release. If you want to contribute, please open an issue or a pull request.

  • Transforms only works with model generated with the code-gen package.
  • You cannot transform a model that has already been transformed
  • - transformation logic assumes base model contains just a list of column names with no aliases or SQL logic added
    
  • You cannot use wild card in fields selection for transforms (e.g. *_id)
  • Limited test coverage
  • No error handling yet

Metadata

Release files for dbt-generator 0.3.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dbt-generator 0.3.2
File Size Uploaded Provenance Actions
dbt_generator-0.3.2.tar.gz 8.5 kB Without provenance Details for dbt_generator-0.3.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dbt-generator 0.3.2
File Interpreter ABI Platform Actions
dbt_generator-0.3.2-py3-none-any.whl Python 3 none any Details for dbt_generator-0.3.2-py3-none-any.whl

Total release size: 18.5 kB

Release files / dbt_generator-0.3.2.tar.gz

Download URL dbt_generator-0.3.2.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
260f608322d44ce6c0ff5dcb8557e131db3fb7d574f959639fc56612bd42a367
BLAKE2b-256 checksum
How to use checksums
1671930b1cb729eedea82cec46c79c9c542c4a795d26f4548a7019cbb8a33df8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.8.1 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Release files / dbt_generator-0.3.2-py3-none-any.whl

Download URL dbt_generator-0.3.2-py3-none-any.whl
Size 10.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
08a479ba543116f67bfcd633d0274be9350f42a56394890ecbcac306d05ab04f
BLAKE2b-256 checksum
How to use checksums
338bea9d4d9621b72c5ff705fba5f451ac9929e98b067ce74b9b8a4621329fbb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.8.1 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Security for dbt-generator 0.3.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page