Skip to main content

A lightweight SQL transformation tool for Databricks SQL

Project description

dbx-sql-runner

A lightweight, library-first SQL transformation tool for Databricks SQL, inspired by DBT.

Features

  • Simple SQL Models: Just write .sql files. No complex boilerplate.
  • Automated Dependency Management: Reference other models using {upstream_model} and let the runner build the DAG for you.
  • Environment Aware: Seamlessly switch between Dev and Prod using profiles.yml and Environment Variables.
  • Library Design: Import dbx_sql_runner in your Python scripts (great for Airflow/Databricks Jobs) or run it via CLI.
  • Flexible Sources: Define external tables in profiles.yml and reference them as {source_name} in your SQL.
  • Automated Linting: Built-in linter (using Ruff) to ensure code quality.

Installation

Development

To install the project in editable mode:

pip install -e .

Running Tests

To run the automated test suite:

pip install .[dev]
python -m pytest

Production

To install the package normally:

pip install dbx-sql-runner

Configuration (profiles.yml)

Create a profiles.yml file to store your credentials. Do not commit this file to version control.

server_hostname: "dbc-xxxxxxxx-xxxx.cloud.databricks.com"
http_path: "/sql/1.0/warehouses/xxxxxxxxxxxxxxxx"
access_token: "${DBX_ACCESS_TOKEN}"  # Env var expansion supported for any field
catalog: "my_catalog"
schema: "my_schema"
sources:
    # keys here can be used in SQL as {my_source}
    my_source: "prod_catalog.schema.table"
    raw_sales: "raw_data.sales_table"

Usage

1. CLI (Easiest)

Run your project from the command line. By default, it looks for profiles.yml in the current directory.

# Initialize a new project
dbx-sql-runner init my_project

# Run with default profile (profiles.yml)
dbx-sql-runner run

# Run with custom profile
dbx-sql-runner run --profile my_config.yml

# Preview execution plan
dbx-sql-runner build

2. Python (Advanced)

For fine-grained control (e.g., inside a Databricks Job):

from dbx_sql_runner.api import run_project

# Run models in the 'models/' directory using the config from 'profiles.yml'
run_project(models_dir="models", config_path="profiles.yml")

Project Structure

.
├── models/                  # SQL files (.sql)
│   └── example.sql
├── dbx_sql_runner/          # Library source code
│   ├── adapters/            # Database Adapters
│   ├── api.py               # Public API
│   ├── cli.py               # Command Line Interface
│   ├── exceptions.py        # Custom Exceptions
│   ├── linter.py            # Linting Logic
│   ├── models.py            # Data Models
│   ├── project.py           # Model Loading & DAG
│   ├── runner.py            # Execution Orchestrator
│   └── scaffold.py          # Project Scaffolding
├── profiles.yml             # Configuration (gitignored)
├── pyproject.toml           # Project metadata
└── README.md

Defining Models

Create .sql files in your models/ directory.

  • Use header comments for metadata.
  • Use {upstream_model} syntax for references (automatically infers dependency).
  • Use {source_name} to reference sources defined in profiles.yml.
-- name: my_table
-- materialized: table
-- partition_by: date, region

/*
    Multi-line comments are supported.
    Refer to upstream models: {upstream_model}
    Refer to sources: {my_source}
*/

SELECT 
    id,
    amount
FROM {source_view}
WHERE id > 100

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

dbx_sql_runner-0.2.1.tar.gz (20.3 kB view details)

Uploaded Source

Built Distribution

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

dbx_sql_runner-0.2.1-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

Details for the file dbx_sql_runner-0.2.1.tar.gz.

File metadata

  • Download URL: dbx_sql_runner-0.2.1.tar.gz
  • Upload date:
  • Size: 20.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dbx_sql_runner-0.2.1.tar.gz
Algorithm Hash digest
SHA256 6a6c0893beb4d8d102d042edf714e89a8fb838c25618add9264f81ec2f91eafc
MD5 c19e563b390e480ffadecd2dc356a158
BLAKE2b-256 370164ad7b5b1ceb4d881f1a258363d92749fe64d33804be29109387b72ac627

See more details on using hashes here.

Provenance

The following attestation bundles were made for dbx_sql_runner-0.2.1.tar.gz:

Publisher: publish.yml on munish7771/dbx-sql-runner

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

File details

Details for the file dbx_sql_runner-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: dbx_sql_runner-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 16.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dbx_sql_runner-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ef65b528f7c337a8313b724dbca119e0a282f538cdc41cb24b2fce71a2c50822
MD5 764de7462f4ed635ee749d157ab6d4fd
BLAKE2b-256 4ef90e406ea079617ffff3cc7135bdb16d78fa844eaf83fbc7401dee5bb97301

See more details on using hashes here.

Provenance

The following attestation bundles were made for dbx_sql_runner-0.2.1-py3-none-any.whl:

Publisher: publish.yml on munish7771/dbx-sql-runner

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