Skip to main content

Universal semantic layer - import from Cube, dbt, LookML, Hex, and more

Project description

Sidemantic

SQL-first semantic layer for consistent metrics across your data stack. Compatible with many other semantic model formats.

  • Formats: Sidemantic, Cube, MetricFlow (dbt), LookML, Hex, Rill, Superset, Omni, BSL, Snowflake Cortex, Malloy
  • Databases: DuckDB, MotherDuck, PostgreSQL, BigQuery, Snowflake, ClickHouse, Databricks, Spark SQL

Documentation | GitHub | Discord | Demo (50+ MB download)

Jupyter Widget Preview

Should I use Sidemantic

As you might notice, Sidemantic is a very ambitious and young semantic layer project. You will likely encounter some rough patches, especially with the more exotic features like converting between semantic model formats.

For the time being it is recommended to use one of the formats that Sidemantic can read as your source of truth.

Issue reports are much appreciated if you try out Sidemantic and hit a snag 🫡

Quickstart

Install:

uv add sidemantic

Malloy support (uv):

uv add "sidemantic[malloy]"

Notebook widget (uv):

uv add "sidemantic[widget]" jupyterlab
uv run jupyter lab

Marimo (uv):

uv add "sidemantic[widget]" marimo
uv run marimo edit
import duckdb
from sidemantic.widget import MetricsExplorer

conn = duckdb.connect(":memory:")
conn.execute("create table t as select 1 as value, 'a' as category, date '2024-01-01' as d")
MetricsExplorer(conn.table("t"), time_dimension="d")

Define models in SQL, YAML, or Python:

SQL (orders.sql)
MODEL (name orders, table orders, primary_key order_id);
DIMENSION (name status, type categorical);
DIMENSION (name order_date, type time, granularity day);
METRIC (name revenue, agg sum, sql amount);
METRIC (name order_count, agg count);
YAML (orders.yml)
models:
  - name: orders
    table: orders
    primary_key: order_id
    dimensions:
      - name: status
        type: categorical
      - name: order_date
        type: time
        granularity: day
    metrics:
      - name: revenue
        agg: sum
        sql: amount
      - name: order_count
        agg: count
Python (programmatic)
from sidemantic import Model, Dimension, Metric

orders = Model(
    name="orders",
    table="orders",
    primary_key="order_id",
    dimensions=[
        Dimension(name="status", type="categorical"),
        Dimension(name="order_date", type="time", granularity="day"),
    ],
    metrics=[
        Metric(name="revenue", agg="sum", sql="amount"),
        Metric(name="order_count", agg="count"),
    ]
)

Query via CLI:

sidemantic query "SELECT revenue, status FROM orders" --db data.duckdb

Or Python API:

from sidemantic import SemanticLayer, load_from_directory

layer = SemanticLayer(connection="duckdb:///data.duckdb")
load_from_directory(layer, "models/")
result = layer.sql("SELECT revenue, status FROM orders")

CLI

# Query
sidemantic query "SELECT revenue FROM orders" --db data.duckdb

# Interactive workbench (TUI with SQL editor + charts)
sidemantic workbench models/ --db data.duckdb

# PostgreSQL server (connect Tableau, DBeaver, etc.)
sidemantic serve models/ --port 5433

# Validate definitions
sidemantic validate models/

# Model info
sidemantic info models/

# Pre-aggregation recommendations
sidemantic preagg recommend --db data.duckdb

# Migrate SQL queries to semantic layer
sidemantic migrator --queries legacy/ --generate-models output/

Demos

Workbench (TUI with SQL editor + charts):

uvx sidemantic workbench --demo

PostgreSQL server (connect Tableau, DBeaver, etc.):

uvx sidemantic serve --demo --port 5433

Colab notebooks:

Open in Colab SQL + DuckDB

Open in Colab LookML multi-entity

SQL syntax:

uv run https://raw.githubusercontent.com/sidequery/sidemantic/main/examples/sql/sql_syntax_example.py

Comprehensive demo:

uv run https://raw.githubusercontent.com/sidequery/sidemantic/main/examples/advanced/comprehensive_demo.py

Symmetric aggregates:

uv run https://raw.githubusercontent.com/sidequery/sidemantic/main/examples/features/symmetric_aggregates_example.py

Superset with DuckDB:

git clone https://github.com/sidequery/sidemantic.git && cd sidemantic
uv run examples/superset_demo/run_demo.py

Cube Playground:

git clone https://github.com/sidequery/sidemantic.git && cd sidemantic
uv run examples/cube_demo/run_demo.py

Rill Developer:

git clone https://github.com/sidequery/sidemantic.git && cd sidemantic
uv run examples/rill_demo/run_demo.py

See examples/ for more.

Core Features

  • SQL query interface with automatic rewriting
  • Automatic joins across models
  • Multi-format adapters (Cube, MetricFlow, LookML, Hex, Rill, Superset, Omni, BSL)
  • SQLGlot-based SQL generation and transpilation
  • Pydantic validation and type safety
  • Pre-aggregations with automatic routing
  • Predicate pushdown for faster queries
  • Segments and metric-level filters
  • Jinja2 templating for dynamic SQL
  • PostgreSQL wire protocol server for BI tools

Multi-Format Support

Auto-detects: Sidemantic (SQL/YAML), Cube, MetricFlow (dbt), LookML, Hex, Rill, Superset, Omni, BSL

sidemantic query "SELECT revenue FROM orders" --models ./my_models
from sidemantic import SemanticLayer, load_from_directory

layer = SemanticLayer(connection="duckdb:///data.duckdb")
load_from_directory(layer, "my_models/")  # Auto-detects formats

Databases

Database Status Installation
DuckDB built-in
MotherDuck built-in
PostgreSQL uv add sidemantic[postgres]
BigQuery uv add sidemantic[bigquery]
Snowflake uv add sidemantic[snowflake]
ClickHouse uv add sidemantic[clickhouse]
Databricks uv add sidemantic[databricks]
Spark SQL uv add sidemantic[spark]

Testing

uv run pytest -v

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

sidemantic-0.5.10.tar.gz (988.4 kB view details)

Uploaded Source

Built Distribution

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

sidemantic-0.5.10-py3-none-any.whl (465.1 kB view details)

Uploaded Python 3

File details

Details for the file sidemantic-0.5.10.tar.gz.

File metadata

  • Download URL: sidemantic-0.5.10.tar.gz
  • Upload date:
  • Size: 988.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for sidemantic-0.5.10.tar.gz
Algorithm Hash digest
SHA256 3dd345d542c70d761cb6ebad98ec9b7169c8ac9f1a9da6024211e0e359955a04
MD5 96acb199be105c61b2e7bf9f7f5480bd
BLAKE2b-256 0843d389f179535ad51ff25c7819fc6a9d69c8e22b39215558dedbeae2e64091

See more details on using hashes here.

File details

Details for the file sidemantic-0.5.10-py3-none-any.whl.

File metadata

  • Download URL: sidemantic-0.5.10-py3-none-any.whl
  • Upload date:
  • Size: 465.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for sidemantic-0.5.10-py3-none-any.whl
Algorithm Hash digest
SHA256 9f6909faf5d4d865a68d775986f2ba933c61dd65ae59fd8a0d60e3462ddf25a0
MD5 9c6618799fe0159b3b2922ab1a355d06
BLAKE2b-256 bdf25d95abc9893da7e3595d6e2974c01684f57f2ea96b05d0bc76282595b85e

See more details on using hashes here.

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