Universal SQL-first semantic layer in Python. Imports from Cube/LookML/dbt/Hex/Rill/Malloy, queries against DuckDB/Postgres/BigQuery/Snowflake/etc.
- sqlctx usage is overwhelmingly CLI-first in practice (roughly 95% CLI usage).
- Default to
sqlctxCLI workflows (validate,info,query,migrate, etc.). - Treat Python API examples as secondary, advanced automation paths, not the default onboarding path.
Main Python package: sqlctx/
core/- SemanticLayer, Model, Dimension, Metric, SemanticGraphadapters/- Format parsers (Cube, LookML, MetricFlow, Hex, Rill, Malloy, etc.)db/- Database adapterssql/- SQL generation and query rewritingwidget/,server/,workbench/,mcp_server.py- Optional features with lazy imports
Rust runtime and DuckDB extension (experimental):
sqlctx-rs/- Rust native runtime, also built as thesqlctx-rsPython extension. Python opts in throughsqlctx/rust_bridge.py, the optionalrustextra, and--engine rust|auto; Python stays the default engine (seedocs/rust-engine-mode.md).sqlctx-duckdb/- DuckDB extension wrapping sqlctx-rs
CI runs the Rust and DuckDB jobs when their dirs change, and the Rust jobs also when the Python code they exercise changes (bridge, core, SQL, CLI; see the paths filter in .github/workflows/ci.yml).
Update BOTH when releasing:
pyproject.toml:version = "X.Y.Z"sqlctx/__init__.py:__version__ = "X.Y.Z"
Match validation scope to the change instead of running the entire suite automatically.
- For small, localized changes, run ruff on the changed Python files and the narrowest relevant tests. This is the default.
- Expand to the affected package or subsystem when shared code, planners, adapters, or fixtures may have broader impact.
- Run the full CI-equivalent sequence only when explicitly requested, preparing a release, changing dependencies/CI/tooling, making a broad cross-cutting refactor, or when targeted checks cannot bound the blast radius.
- Do not rerun the full suite for a small follow-up on a branch that already had a green full run when targeted tests cover the follow-up.
- Before handoff, report exactly what ran and what was left to CI.
When full CI parity is warranted, run these commands in order:
# Run these in order:
uv sync --extra dev
uv run python - <<'PY'
import sys
from sqlctx import Dimension, Metric, Model
assert Model.__name__ == "Model"
assert Dimension.__name__ == "Dimension"
assert Metric.__name__ == "Metric"
assert "sqlctx_dax" not in sys.modules
PY
uv sync --extra dev --extra dax
uv run ruff check . --exclude docs/_extensions --exclude sqlctx-duckdb/extension-ci-tools --exclude sqlctx-duckdb/scripts --exclude sqlctx-duckdb/duckdb --exclude sqlctx/adapters/malloy_grammar --exclude sqlctx/adapters/holistics_grammar
uv run ruff format --check . --exclude docs/_extensions --exclude sqlctx-duckdb/extension-ci-tools --exclude sqlctx-duckdb/scripts --exclude sqlctx-duckdb/duckdb --exclude sqlctx/adapters/malloy_grammar --exclude sqlctx/adapters/holistics_grammar
uv run python -m playwright install --with-deps chromium
uv run pytest -vIf any fail, fix them:
# Fix ruff issues
uv run ruff check --fix . --exclude docs/_extensions --exclude sqlctx-duckdb/extension-ci-tools --exclude sqlctx-duckdb/scripts --exclude sqlctx-duckdb/duckdb --exclude sqlctx/adapters/malloy_grammar --exclude sqlctx/adapters/holistics_grammar
uv run ruff format . --exclude docs/_extensions --exclude sqlctx-duckdb/extension-ci-tools --exclude sqlctx-duckdb/scripts --exclude sqlctx-duckdb/duckdb --exclude sqlctx/adapters/malloy_grammar --exclude sqlctx/adapters/holistics_grammarPRs: Do not include test commands in PR bodies unless explicitly requested.
Why this matters:
- Targeted checks keep small changes fast while still covering the affected behavior
- CI runs the full matrix and remains the final integration gate
- CI installs with
uv sync --extra dev, so ruff and other CI tools must be in[project.optional-dependencies] dev [dependency-groups] devalone is not enough (uv-only; CI reads thedevextra)
- Use
uvfor all Python package management - Dev tools such as ruff go in the
devextra ([project.optional-dependencies] dev);[dependency-groups] devmirrors them for local uv use - DO NOT add dev tools to main dependencies unless explicitly requested
- Optional features use
[project.optional-dependencies]:workbench- textual, plotext, textual-plotext (for TUI, NOT Pyodide compatible)serve- riffq, pyarrow (for the PostgreSQL wire server,sqlctx server postgres; NOT Pyodide compatible)api/mcp- fastapi, uvicorn, pyarrow / mcp[cli] (forsqlctx serve,server api,server mcp)dev- pytest, ruff, pandas, numpy (for development)
CRITICAL: Pyodide Compatibility Rules
- Core dependencies (in main
dependencieslist) MUST work in Pyodide/WASM - Optional dependencies can use packages incompatible with Pyodide (textual, riffq, pyarrow, mcp)
- ALL imports of optional deps MUST be lazy (inside functions, NOT at module level)
- Test:
from sqlctx import Model, Dimension, Metricmust work without any optional deps
Import Structure:
sqlctx/__init__.py- Only imports core classes (Model, Dimension, etc.)sqlctx/cli.py- Imports typer (core dep) at top, workbench/server imports inside command functionssqlctx/workbench/__init__.py- Lazy imports textual insiderun_workbench()functionsqlctx/server/- Not imported bysqlctx/__init__.py;server.py/connection.py(riffq) load only forsqlctx server postgres, and the dependency-freecommon.pyis shared with the API, MCP, and chart modules
Pyodide install path (docs/pyodide.md, .github/workflows/pyodide-test.yml):
- Pyodide's bundled
pydantic,pyyaml, andjinja2are loaded first;sqlglot,lkml, andinflectare installed withdeps=False - Bundled Pyodide packages pin their own versions (including typing-extensions), so a core dep that needs newer versions breaks this path
Version constraints with "PYODIDE:" comments are REQUIRED:
- Heavy deps (textual, riffq, mcp) are optional to avoid Pyodide conflicts
- Pyodide CI builds local wheel and installs it with
deps=False - This ensures code changes are tested in Pyodide before publish
- If adding new core deps, check they work in Pyodide or make them optional
If Pyodide CI fails:
- Check if a dep version changed that requires newer typing-extensions
- Either constrain that dep OR update the install sequence in
docs/pyodide.mdandpyodide-test.ymltogether - CI installs local wheel to test current code, not PyPI version
Use the validation scope above. Prefer focused test paths or test names for localized changes; reserve uv run pytest -v for cases that warrant full CI parity.
gh workflow run publish.yml- Breaking ruff - Always ensure ruff is installed in dev dependencies
- Pyodide compatibility - Keep heavy deps (textual, pygments) optional
- Not linting - Format and lint EVERY TIME before commit