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.

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

DocumentationGitHub

Quickstart

Install:

uv add sidemantic

Define your semantic layer (SQL shown; YAML and Python are also supported):

-- semantic_layer.sql
MODEL (name orders, table orders, primary_key order_id);

DIMENSION (name status, type categorical, sql status);
DIMENSION (name order_date, type time, sql created_at, granularity day);

METRIC (name revenue, agg sum, sql amount);
METRIC (name order_count, agg count);

Query with familiar SQL:

from sidemantic import SemanticLayer

layer = SemanticLayer.from_yaml("semantic_layer.sql", connection="duckdb:///data.duckdb")

result = layer.sql("""
    select revenue, status
    from orders
    where status = 'completed'
""")

rows = result.fetchall()

Demos

Colab:

Demo Open in Colab
SQL model definitions + DuckDB Open in Colab
LookML multi-entity + DuckDB + chart Open in Colab

Local notebooks:

  • examples/sidemantic_sql_duckdb_demo.ipynb
  • examples/lookml_multi_entity_duckdb_demo.ipynb

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

Formats and Databases

Formats

Import from: Sidemantic (native), Cube, MetricFlow (dbt), LookML (Looker), Hex, Rill, Superset (Apache), Omni, BSL (Boring Semantic Layer).

Adapter compatibility details: https://sidemantic.com

Databases

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

CLI

# Interactive workbench
uvx sidemantic workbench --demo

# Run a query
sidemantic query semantic_models/ --sql "select orders.revenue from orders"

# PostgreSQL wire protocol server
sidemantic serve semantic_models/ --port 5433

# Validate definitions
sidemantic validate semantic_models/

Load From Multiple Formats

from sidemantic import SemanticLayer, load_from_directory

layer = SemanticLayer(connection="duckdb:///data.duckdb")
load_from_directory(layer, "semantic_models/")

result = layer.query(
    metrics=["orders.revenue"],
    dimensions=["customers.region"]
)

Examples

See examples/ directory:

  • sql_query_example.py - SQL query interface demonstration
  • basic_example.py - Core usage patterns
  • multi_format_demo/ - Same model in different formats (Cube, Hex, LookML, BSL)

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.4.2.tar.gz (362.5 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.4.2-py3-none-any.whl (227.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sidemantic-0.4.2.tar.gz
  • Upload date:
  • Size: 362.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","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.4.2.tar.gz
Algorithm Hash digest
SHA256 c364cc6c3a563102eabb1a064e6b2cf9bbd93ffdade788ba4d6969b8fd124e86
MD5 c4c83a71d21cdf6477bf469df43755b9
BLAKE2b-256 69ed700e15605992e6bf51fa82786fcffe15d29771c88f82e5dea255012e417c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sidemantic-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 227.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","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.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c001d5377328ba3aec34f1e0333da1fe9b9c81a0f34dcd3252ddab1975b2d479
MD5 f132815d47190954616f1001000e5b88
BLAKE2b-256 676ce9554e663ffc5b557c0bdb14e37d5b3b62008779679a7a902e79be29c97a

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