sqlctx
sqlctx is an open-source semantic runtime. Define governed metrics once—or import the semantic models you already have—and query them consistently from SQL, the CLI, Python, HTTP, PostgreSQL clients, notebooks, BI tools, and AI agents.
- Bring existing models: Power BI TMDL/DAX, Cube, dbt MetricFlow, LookML, Hex, Rill, Superset, Omni, BSL, GoodData LDM, Snowflake Cortex, Malloy, Apache Ossie, AtScale SML, and ThoughtSpot TML
- Or author natively: concise YAML, semantic SQL DDL, or Python
- Run on your warehouse: DuckDB, MotherDuck, PostgreSQL, BigQuery, Snowflake, ClickHouse, Databricks, Spark SQL, and ADBC sources
- Consume metrics anywhere: semantic SQL, CLI, Python, HTTP/Arrow, PostgreSQL wire protocol, MCP, notebooks, TypeScript/WASM, and embedded analytics
Documentation | GitHub | Docker | Discord | Demo (50+ MB data download, runs in your browser with Pyodide + DuckDB)

sqlctx ships Claude Code and Codex plugin metadata for two skills (modeler and webapp-builder). See Agent Plugin below to install.
Contributors working on browser surfaces should read the UI architecture and canonical ownership map.
60-second quickstart
Run the published sqlctx package with uvx.
See it working before writing anything — one command creates a complete demo
project (models, sample DuckDB data, golden tests) and runs a first query:
uvx sqlctx demo
Start from your own data — sqlctx introspects it and generates models with
inferred dimensions, metrics, and relationships:
uvx sqlctx init analytics --from 'data/*.csv' # also Parquet, JSON, DuckDB
cd analytics
uvx sqlctx query "SELECT orders.record_count FROM orders"
uvx sqlctx test # golden-query assertions
uvx sqlctx validate --live # models vs. actual database schema
uvx --from "sqlctx[api,mcp]" sqlctx serve # web UI + HTTP API + MCP on one port
Or write a model by hand. Create models/orders.yml:
models:
- name: orders
sql: |
select * from (values
(1, 'paid', 120.00),
(2, 'paid', 80.00),
(3, 'pending', 50.00)
) as t(id, status, amount)
primary_key: id
dimensions:
- name: status
type: categorical
sql: status
metrics:
- name: revenue
agg: sum
sql: amount
- name: order_count
agg: count
Query it directly—no database setup or package installation required:
uvx sqlctx query \
"SELECT orders.status, orders.revenue, orders.order_count
FROM orders
ORDER BY orders.status" \
--models ./models
status,revenue,order_count
paid,200.00,2
pending,50.00,1
From here, inspect generated warehouse SQL or open an interactive explorer:
# Compile without executing
uvx sqlctx query \
"SELECT orders.status, orders.revenue FROM orders" \
--models ./models --dry-run
# Explore in the terminal
uvx --from "sqlctx[workbench]" sqlctx workbench ./models
Choose your path
- Import existing semantic models: point sqlctx at a Cube, MetricFlow, LookML, Power BI, Malloy, Rill, or other supported project. Start with the adapter guide.
- Model tables or SQL: continue with models, dimensions, metrics, and relationships.
- Query governed metrics: use the CLI, semantic SQL, or Python API.
- Explore data: launch the terminal workbench, notebook widget, or browser UI.
- Serve other tools: expose models over the HTTP API, PostgreSQL wire protocol, or MCP server.
Install sqlctx in a project with uv add sqlctx. Optional features are packaged as extras:
- Interfaces:
api (HTTP API and sqlctx serve), mcp (MCP server), apps (MCP apps with charts), serve (PostgreSQL wire protocol server), workbench (terminal UI), widget (Jupyter widget), charts (Altair charts for MCP chart tools), and lsp (language server)
- Model formats:
lookml, metricflow, malloy, dax (Power BI TMDL/DAX), and ossie (Apache Ossie schema validation)
- Databases:
postgres, bigquery, snowflake, clickhouse, databricks, spark, and adbc, or all-databases for all of them
- Engine:
rust (Rust engine) and fast (compiled SQLGlot)
- Bundle:
full (every interface, format, and engine extra except serve, fast, and the databases)