Skip to main content

DBT extension for Metaflow

Project description

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

The command metaflow dbt examples will pull example flows to your working directory under metaflow-dbt-examples.

Follow the README.md under the examples directory for more instructions.

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

metaflow_dbt-1.0.7.tar.gz (97.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

metaflow_dbt-1.0.7-py3-none-any.whl (113.3 kB view details)

Uploaded Python 3

File details

Details for the file metaflow_dbt-1.0.7.tar.gz.

File metadata

  • Download URL: metaflow_dbt-1.0.7.tar.gz
  • Upload date:
  • Size: 97.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for metaflow_dbt-1.0.7.tar.gz
Algorithm Hash digest
SHA256 3b8e1fd2025095cea99465da7215f4d86658032faabe8da30ad79923eb876ebd
MD5 f7180f4ac07b414ca854d3b454e23bca
BLAKE2b-256 27d7df67ddc2f8b2f19d0152e6fe68f32425ecbb07b88c4822d7a37ed1980aaa

See more details on using hashes here.

Provenance

The following attestation bundles were made for metaflow_dbt-1.0.7.tar.gz:

Publisher: publish.yml on outerbounds/metaflow-dbt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file metaflow_dbt-1.0.7-py3-none-any.whl.

File metadata

  • Download URL: metaflow_dbt-1.0.7-py3-none-any.whl
  • Upload date:
  • Size: 113.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for metaflow_dbt-1.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 c5d6326080ff5aff4788758c2bc4856a5d00654c68f194a7cf4f8ab83f1213e6
MD5 e5322caa83e4f8b45010f813a078cc9b
BLAKE2b-256 180d2fea0aa00e95b115c3839f8a1839a3ecae86c29e45252ec58068082a8583

See more details on using hashes here.

Provenance

The following attestation bundles were made for metaflow_dbt-1.0.7-py3-none-any.whl:

Publisher: publish.yml on outerbounds/metaflow-dbt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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