Skip to main content

DBT extension for Metaflow

This extension adds support for executing DBT models as part of steps in Metaflow Flows via decorators.

Basic usage

Having a dbt_project.yml as part of your Flow project will allow executing dbt run as a pre-step to any task by simply adding the decorator to a step.

@dbt
@step
def start(self):
    # DBT Models have been run when step execution starts

    self.next(self.second_step)

If you only want to run a specific model as part of a step, you can specify this with the models= attribute

@dbt(models="customers")

Configuration options

Project directory

You might want to keep the DBT project separately nested within the Flow project. In these cases you would need to specify the location of the DBT project folder, due to the way project lookup works. This can be done by specifying the project location as a relative or absolute path within the decorator

@dbt(models="customers", project_dir="./dbt_project")

Supplying credentials

When deploying a DBT flow to be executed remotely, we do not want to bundle up sensitive credentials into the code package. Therefore a plain text profiles.yml will not suffice. We can utilize the environment variable replacement that DBT offers to get around this.

example profiles:

dbt_decorator:
  outputs:
    dev:
      type: postgres
      threads: 1
      host: localhost
      port: 5432
      user: "{{ env_var('DBT_POSTGRES_USER') }}"
      pass: "{{ env_var('DBT_POSTGRES_PW') }}"
      dbname: dbt_decorator
      schema: dev_jaffle_schema

    prod:
      type: postgres
      threads: 1
      host: localhost
      port: 5432
      user: "{{ env_var('DBT_POSTGRES_USER') }}"
      pass: "{{ env_var('DBT_POSTGRES_PW') }}"
      dbname: dbt_decorator
      schema: prod_jaffle_schema

  target: dev

Note: any profiles.yml in the flow project folder will be packaged, so make sure that they do not contain sensitive secrets.

We can supply the environment variables in various ways, for example

  • having them already present in the execution environment
  • supplying them with the @environment decorator in the flow (this still ends up bundling secrets into the package, but is good for testing)
  • hydrating environment variables with the @secrets decorator from a secret manager.

Examples

Check out the example flows in the /examples folder for detailed usage.

Metadata

Release files for metaflow-dbt-extension 1.0.0

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

Source distribution (sdist)

Source distribution for metaflow-dbt-extension 1.0.0
File Size Uploaded Provenance
metaflow-dbt-extension-1.0.0.tar.gz 19.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for metaflow-dbt-extension 1.0.0
File Interpreter ABI Platform
metaflow_dbt_extension-1.0.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 42.6 kB

Release files / metaflow-dbt-extension-1.0.0.tar.gz

Download URL metaflow-dbt-extension-1.0.0.tar.gz
Size 19.9 kB
Tags Source
SHA-256 checksum
How to use checksums
fbb0be16152e7a73d35a746084e6095e42622507efcc81099fc990d1452ae524
BLAKE2b-256 checksum
How to use checksums
ac347bfad26fae547fbdfa59655064881daf3419d99d9f7ed8e00bf4ae664162
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.5

Release files / metaflow_dbt_extension-1.0.0-py2.py3-none-any.whl

Download URL metaflow_dbt_extension-1.0.0-py2.py3-none-any.whl
Size 22.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
af49997ec6d30821ac099a50611225682c4c25d08abdcb1be57a06512d40658e
BLAKE2b-256 checksum
How to use checksums
f071b771c79c2a1c2b1e3e298f81e2d4bfecef44740e5a9759f5a80d5c940520
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.5

Security for metaflow-dbt-extension 1.0.0

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.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

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