Skip to main content

A dbt companion for unit testing, column-level lineage, and more.

Project description

dbtmeshification

A Python package that enhances dbt-core projects with SQLMesh-inspired unit testing capabilities powered by sqlglot and DuckDB.

Features

  • CTE-Level Testing: Test individual CTEs within your dbt models, not just the final output
  • Fast Local Execution: Run tests in-memory using DuckDB - no data warehouse required
  • Mock Data Support: Define mock inputs inline in YAML spec files
  • SQL Dialect Transpilation: Automatically transpile from your dbt dialect to DuckDB
  • Clean CLI: Simple mesh test command integrates into your workflow

Installation

pip install dbtmeshification

Quick Start

  1. Ensure your dbt project is compiled:

    cd your-dbt-project
    dbt compile
    
  2. Create a specs directory in your dbt project:

    mkdir specs
    
  3. Write a test spec (e.g., specs/my_model.yml):

    model: my_model
    
    tests:
      - name: "test_my_cte"
        target: "my_cte_name"
        mocks:
          - name: "upstream_cte"
            format: "inline"
            content:
              - {id: 1, value: "test"}
              - {id: 2, value: "data"}
        expect:
          format: "inline"
          content:
            - {id: 1, result: "processed"}
    
  4. Run tests:

    mesh test
    

Usage

# Run all tests
mesh test

# Run tests for a specific model
mesh test --model my_model

# Specify dbt project directory
mesh test --project-dir /path/to/dbt/project

# Specify specs directory
mesh test --specs-dir /path/to/specs

# Use persistent DuckDB file
mesh test --db-file test.db

How It Works

  1. Reads your compiled dbt model SQL from target/manifest.json
  2. Parses the SQL to identify CTEs using sqlglot
  3. Loads mock data into DuckDB tables
  4. Rewrites queries to reference mock tables instead of upstream CTEs
  5. Executes tests in DuckDB and compares results

Requirements

  • Python >= 3.8
  • dbt-core
  • A compiled dbt project (dbt compile must be run first)

Development Status

⚠️ Alpha Release - This is an early version. APIs may change.

Current limitations:

  • Only inline mock data format supported
  • Simple equality-based result comparison
  • No support for dbt sources/refs mocking yet

License

MIT

Contributing

Issues and pull requests welcome at https://github.com/yourusername/dbtmeshification

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

dbtmeshification-0.0.1.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

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

dbtmeshification-0.0.1-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

Details for the file dbtmeshification-0.0.1.tar.gz.

File metadata

  • Download URL: dbtmeshification-0.0.1.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.2

File hashes

Hashes for dbtmeshification-0.0.1.tar.gz
Algorithm Hash digest
SHA256 51cda1c56ddeeb7d72820320fa5c55ca7e18bbde8ea99c77bedb6bd0e632be20
MD5 19d48aa0189249c66bf14c42980c1326
BLAKE2b-256 732142abac07ffcf29ed1406fefefe279f70c78b41ab4460d9e09ca39bd64cda

See more details on using hashes here.

File details

Details for the file dbtmeshification-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for dbtmeshification-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c7b1c5bf7be51d072051b5a666f33abfbb0e3ddcc4276a0184571769e6f33bd0
MD5 7a20f59f049e9bbc3711131d4ebb18c3
BLAKE2b-256 c8681e93f3aa6ded03d3567ffa95ef2e7dae790c7309b8bbfd8693799f1e8826

See more details on using hashes here.

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