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.3.tar.gz (363.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.4.3-py3-none-any.whl (228.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sidemantic-0.4.3.tar.gz
  • Upload date:
  • Size: 363.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.4.3.tar.gz
Algorithm Hash digest
SHA256 86f5272607c92ed2c9ceb4af338e76f51cfe1921c7cf3e613badb1eec7a5a886
MD5 8b596f732be6560cb758dbe3e0e906cc
BLAKE2b-256 958dfc9dfe976f49a815889202970bbcda545a01fd0762e7bf118e138b95f72d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sidemantic-0.4.3-py3-none-any.whl
  • Upload date:
  • Size: 228.8 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 88e7b6cc9f589b9bd39fb710a35589f1e00fc14f033b0d9e17dc0eab674ebf93
MD5 ee57f303c5254bc7d8fad9ef85e5bf3b
BLAKE2b-256 025a55698d2c0cf2ff31f293c731ad7468225a520d69b52afe4d6a6675358347

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