dbt-metricflow

0.11.0 · active · verified Thu Apr 16

dbt-metricflow is a Python package that bundles dbt-core, MetricFlow, and supported dbt adapters to provide a semantic layer for defining and managing metrics within a dbt project. It compiles metric definitions into reusable SQL, ensuring consistent analysis across data. Part of the Open Semantic Interchange (OSI) initiative, it simplifies metric governance and query generation. The current version is 0.11.0, with a release cadence tied to the underlying dbt-core and MetricFlow libraries, with the bundle aiming to ensure compatibility between them.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to interact with dbt-metricflow functionality through the `dbt sl` CLI commands using Python's `subprocess` module. This is the primary way users query and validate semantic layer definitions. Ensure you have a dbt project with semantic models and metrics configured, and dbt-metricflow (with an appropriate adapter) installed in your environment.

import subprocess
import os

# This assumes a dbt project with semantic models and metrics defined is set up.
# And dbt-metricflow (with an adapter) is installed in the environment.

# Example: List available metrics in your dbt project
print("Listing dbt metrics...")
result = subprocess.run(['dbt', 'sl', 'list', 'metrics'], capture_output=True, text=True, check=False)
print(result.stdout)
if result.stderr:
    print(f"Error: {result.stderr}")

# Example: Validate your semantic layer configurations
print("Running dbt semantic layer health checks...")
result = subprocess.run(['dbt', 'sl', 'health-check'], capture_output=True, text=True, check=False)
print(result.stdout)
if result.stderr:
    print(f"Error: {result.stderr}")

view raw JSON →