SQLMesh: Next-generation data transformation framework

0.234.0 · active · verified Wed Apr 15

SQLMesh is a next-generation data transformation framework designed to ship data quickly, efficiently, and without error. It enables data teams to run and deploy data transformations written in SQL or Python with visibility and control, supporting concepts like virtual data environments, automated testing, and CI/CD. It is backwards compatible with dbt and focuses on semantic understanding of SQL. The project maintains an active development cycle with frequent releases, with 0.234.0 being the latest stable version.

Warnings

Install

Imports

Quickstart

The most common way to get started with SQLMesh is via its CLI. This quickstart demonstrates how to initialize a new project using DuckDB as the local engine and then run your first plan. The `sqlmesh init duckdb` command scaffolds a project, and `sqlmesh plan` shows the proposed changes. For a fully runnable example demonstrating project setup and execution, refer to the official documentation.

import os
# Ensure SQLMesh is installed along with the DuckDB extra
# pip install "sqlmesh[duckdb]"

# Initialize a new SQLMesh project with DuckDB as the engine
# This creates a 'sqlmesh_example' directory with project files
# and sets up a DuckDB connection.
# os.system("sqlmesh init duckdb --path sqlmesh_example")

# Navigate into the project directory (conceptually, in a real script you'd use os.chdir or similar)
# In a terminal, you would run:
# cd sqlmesh_example
# sqlmesh plan

# Simulate a SQL model file: models/full_model.sql
# -- models/full_model.sql
# -- MODEL (
# --   name sqlmesh_example.full_model,
# --   kind FULL
# -- );
# -- SELECT
# --   1 AS id,
# --   'A' AS value;

# To run the plan and apply changes (requires a project initialized by 'sqlmesh init'):
# print("\n--- Running sqlmesh plan ---")
# if os.path.exists('sqlmesh_example'):
#     os.chdir('sqlmesh_example')
#     os.system('sqlmesh plan --no-gaps --auto-apply')
#     print("\n--- Querying the created model (requires DuckDB CLI or connector) ---")
#     # You can query the model using duckdb CLI if installed:
#     # os.system('duckdb sqlmesh.db "SELECT * FROM sqlmesh_example.full_model;"')
# else:
#     print("Please run 'sqlmesh init duckdb' in your terminal first to create the example project.")

print("To get started, run 'sqlmesh init duckdb' in your terminal, then 'cd sqlmesh_example' and 'sqlmesh plan'.")
print("This will create an example project and show you the execution plan.")

view raw JSON →