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

DocumentationGitHubDiscord

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.5.0.tar.gz (379.7 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.0-py3-none-any.whl (245.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sidemantic-0.5.0.tar.gz
  • Upload date:
  • Size: 379.7 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.5.0.tar.gz
Algorithm Hash digest
SHA256 882edd6f56c3514d403a5a115431dc5cf0d341261ae4b76f95b1edbe575d7326
MD5 e6babeae0cb698a456229c23df000da6
BLAKE2b-256 61b2d1d544c9f9b7c8c979ecbcd8cec4741416c4075e85e76729d44a557f344a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sidemantic-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 245.5 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.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 48629f5ff8d09dc6c9cf33847b64c8cb400d093a2a1c1e5cd3353640d3ec0729
MD5 abe076043d1032609f1b7b0acab5ede3
BLAKE2b-256 cad279df567fa1a8d4c77da39e1905d9ab29b70840b83088fd9c54c171a60bd1

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