Batch SQL transformation framework
Project description
Typed, test-first SQL pipelines with change-aware incremental rebuilds.
SQLBuild is a framework for building batch SQL transformation pipelines where correctness and extensibility are first-class concerns.
Key features
- SQL unit tests that chain across models - Mock your sources, assert on the model you care about, and SQLBuild resolves every intermediate model automatically. One test file can be a full integration test across your pipeline.
- Audits that block bad data - Audits run before data reaches the target table. For full table builds, SQLBuild materializes into a staging table and only promotes if audits pass. For incremental models, delta-phase audits validate each batch before DML.
- Python macros, not Jinja - Macros are real Python functions. Testable, debuggable, and composable with standard tooling.
- Change-aware incremental rebuilds - Fingerprint-based query change detection, schema diff tracking, and configurable backfill policies with automatic cascade through the DAG.
- Cursor-based incremental processing - Automatic gap detection and resume. If a model fails for several runs, the next build replays from where it left off. Microbatch mode splits large ranges into configurable batches.
- User-defined functions - SQL and Python UDFs managed as project resources, with table functions for predicate-pushdown-friendly alternatives to final-layer views.
- Environment diffs - Compare schemas and row-level data between environments with
sqb diff prod:dev. - Zero-copy cloning - Branch environments instantly with
sqb clonewithout duplicating data. Nomanifest.jsonrequired. - Custom materializations - Write materialization logic in Python with full framework integration, including audit hooks, schema change signals, and query change detection.
- Path-between selectors -
--select fact_orders~daily_activity_rollupselects every model on the shortest path between two nodes.
Quick start
pip install sqlbuild
# or
uv add sqlbuild
Clone the repo and run the waffle shop example:
git clone https://github.com/chio-labs/sqlbuild.git
cd sqlbuild
uv sync
sqb --project-dir examples/waffle_shop plan
sqb --project-dir examples/waffle_shop build
How it works
- Define your models as SQL files with
MODEL()headers that declare configuration, schema, and audits inline - Compile to resolve references, validate SQL (with SQLGlot), and expand Python macros
- Plan what needs to change based on fingerprints, schema diffs, and backfill policies
- Build by executing the plan: materializing models, validating data before promotion, and ensuring bad data never reaches production
- Iterate with first-class support for chained unit tests, zero-copy cloning, and deferred builds - fast feedback without rebuilding the world
Example
A simple staging model:
MODEL (
materialized view,
tags [staging],
);
SELECT
id AS order_id,
customer_id,
ordered_at,
status
FROM __source("raw_orders")
An incremental model with microbatch processing:
MODEL (
materialized incremental,
incremental_strategy delete_insert,
cursor activity_hour,
cursor_type timestamp,
cursor_grain hour,
cursor_inputs (
fact_orders ordered_at,
),
incremental_mode microbatch,
batch_size 1d,
tags [marts],
);
SELECT
DATE_TRUNC('hour', o.ordered_at) AS activity_hour,
COUNT(*) AS orders_placed,
SUM(o.quantity) AS waffles_ordered
FROM __ref("fact_orders") o
GROUP BY DATE_TRUNC('hour', o.ordered_at)
A chained unit test:
TEST();
WITH
__source__raw_orders AS (
@mock_orders()
),
__source__raw_payments AS (
SELECT 1 AS payment_id, 1 AS order_id, 1500 AS amount_cents, 'credit_card' AS method
),
__expected__fact_orders AS (
SELECT 1 AS order_id, 100 AS customer_id, 1500 AS total_cents,
'credit_card' AS payment_method
)
SELECT 1
Documentation
Full documentation is available at docs.sqlbuild.com.
Contributing
We welcome contributions. Please see CONTRIBUTING.md for guidelines.
License
SQLBuild is licensed under the Apache License 2.0.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sqlbuild-0.7.0.tar.gz.
File metadata
- Download URL: sqlbuild-0.7.0.tar.gz
- Upload date:
- Size: 1.8 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d9f9cc780f05c9d791227ce7fa48529d14ab779d115dc148f29f2ac8ff73e1c
|
|
| MD5 |
ceaea06292b4599b7001a76277e5712b
|
|
| BLAKE2b-256 |
8203e54097772d07c0582ac5f7771439a1bf00e4cfe493033a62e9f774fdb06b
|
Provenance
The following attestation bundles were made for sqlbuild-0.7.0.tar.gz:
Publisher:
publish.yml on chio-labs/sqlbuild
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sqlbuild-0.7.0.tar.gz -
Subject digest:
8d9f9cc780f05c9d791227ce7fa48529d14ab779d115dc148f29f2ac8ff73e1c - Sigstore transparency entry: 1464561270
- Sigstore integration time:
-
Permalink:
chio-labs/sqlbuild@0c14d6f6fc44a5c51d4f9bd08d8bd6e61300cc06 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/chio-labs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0c14d6f6fc44a5c51d4f9bd08d8bd6e61300cc06 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file sqlbuild-0.7.0-py3-none-any.whl.
File metadata
- Download URL: sqlbuild-0.7.0-py3-none-any.whl
- Upload date:
- Size: 460.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
571319a4ec8df364457ab219c4883d7b13a16dbbd255c28a05c60eb550aeeaf0
|
|
| MD5 |
f671e1414e35a28ccca4816024756470
|
|
| BLAKE2b-256 |
e6f7fe0b27850ffc7dcf3ae533dc35d1b8ffa6891cbe06dd261b9c5ef4be4450
|
Provenance
The following attestation bundles were made for sqlbuild-0.7.0-py3-none-any.whl:
Publisher:
publish.yml on chio-labs/sqlbuild
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sqlbuild-0.7.0-py3-none-any.whl -
Subject digest:
571319a4ec8df364457ab219c4883d7b13a16dbbd255c28a05c60eb550aeeaf0 - Sigstore transparency entry: 1464561365
- Sigstore integration time:
-
Permalink:
chio-labs/sqlbuild@0c14d6f6fc44a5c51d4f9bd08d8bd6e61300cc06 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/chio-labs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0c14d6f6fc44a5c51d4f9bd08d8bd6e61300cc06 -
Trigger Event:
workflow_dispatch
-
Statement type: