OpenLineage dbt Integration

1.46.0 · active · verified Fri Apr 17

The `openlineage-dbt` library provides a seamless integration between dbt (data build tool) and OpenLineage, capturing detailed data lineage for dbt models, sources, and exposures. It functions as a dbt adapter, translating dbt operations into OpenLineage events. The current version is 1.46.0 and it typically releases updates to align with new OpenLineage Python client versions and dbt-core major/minor versions, maintaining an active development cadence.

Common errors

Warnings

Install

Imports

Quickstart

To quickly integrate `openlineage-dbt`, you need to install the package along with your specific dbt adapter (e.g., `dbt-snowflake`). Then, configure your `profiles.yml` to use `type: openlineage` and specify the `adapter` it should wrap. Finally, set the `OPENLINEAGE_URL` and `OPENLINEAGE_API_KEY` (if required) environment variables or pass them as CLI arguments when running dbt commands. Lineage events will be sent to the configured OpenLineage backend.

# 1. Install openlineage-dbt and your target dbt adapter (e.g., dbt-snowflake)
# pip install openlineage-dbt dbt-snowflake

# 2. Configure your dbt profiles.yml
# (e.g., ~/.dbt/profiles.yml)
# Add an OpenLineage profile that wraps your actual adapter:
# my_openlineage_profile:
#   target: dev
#   outputs:
#     dev:
#       type: openlineage
#       adapter: snowflake # The actual dbt adapter you are using
#       account: <your_snowflake_account>
#       user: <your_snowflake_user>
#       password: <your_snowflake_password>
#       role: <your_snowflake_role>
#       warehouse: <your_snowflake_warehouse>
#       database: <your_snowflake_database>
#       schema: <your_snowflake_schema>
#       threads: 1

# 3. Set OpenLineage URL (and optionally API Key) as environment variables
#    or pass as CLI arguments.
import os
os.environ['OPENLINEAGE_URL'] = os.environ.get('OPENLINEAGE_URL', 'http://localhost:5000') # Or your Marque URL
os.environ['OPENLINEAGE_API_KEY'] = os.environ.get('OPENLINEAGE_API_KEY', 'your_api_key_if_needed')

# 4. Run dbt with the OpenLineage-enabled profile
# Create a dummy dbt project structure for demonstration
# (assuming you have a dbt project initialized, e.g., 'dbt init my_project')
# For example, create models/example.sql in your dbt project:
# -- models/example.sql
# -- {{ config(materialized='table') }}
# -- select 1 as id

print(f"Running dbt with OpenLineage at {os.environ['OPENLINEAGE_URL']}...")

# Example dbt command (execute from your dbt project root):
# dbt build --profile my_openlineage_profile --target dev
# Or, to ensure lineage is sent:
# dbt build --profile my_openlineage_profile --target dev \
#           --openlineage-url $OPENLINEAGE_URL \
#           --openlineage-api-key $OPENLINEAGE_API_KEY

print("Please execute the dbt command from your terminal to see lineage generation.")
print("Example: dbt build --profile my_openlineage_profile --target dev")

view raw JSON →