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.
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)
  • 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.

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
  • sidemantic/orders.yml - Native YAML example
  • cube/orders.yml - Cube format example
  • metricflow/semantic_models.yml - MetricFlow format example

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.1.tar.gz (356.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.1-py3-none-any.whl (220.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sidemantic-0.4.1.tar.gz
  • Upload date:
  • Size: 356.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","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.1.tar.gz
Algorithm Hash digest
SHA256 4f4c9f595055a04c7ce8a44561b54159c8990c131a38221259cc32e7102a28c0
MD5 60d4c9eaa02df0abb075cebbf5ee3ba9
BLAKE2b-256 098837d78f641608a1ca6e929a64fa5e5d248848409a4886da11bf317f08d572

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sidemantic-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 220.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 aadac3ace1be04fd61ed2dd39380f24b980bf090f25dc123500ac84052c8786d
MD5 da24daa857ae75584958e9630329b5bc
BLAKE2b-256 d2eea031ae2e81db0dcf3e6ad603b74b1d237044918159a2c1553440b2145bf0

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