Skip to main content

A Pythonic ORM for querying data warehouse semantic views (Snowflake, Databricks, DuckDB)

Project description

Semolina

[ Docs ]

The ORM for your Semantic Layer.

Typed models in Python, supporting IDE autocomplete, and a Django-like fluent query interface for the semantic layer of your data warehouse backend.

pip install semolina
pip install semolina[snowflake]
pip install semolina[databricks]

A model maps to a semantic view in your warehouse.

from semolina import (
    SemanticView,
    Metric,
    Dimension,
)


class Sales(SemanticView, view="sales"):
    revenue = Metric()
    cost = Metric()
    country = Dimension()
    region = Dimension()

Semolina needs an engine to talk to your warehouse. An engine owns one connection pool and the dialect for a backend. Build one with create_engine and register it before running any queries:

from semolina import create_engine, register

engine = create_engine(
    "default"
)  # reads [connections.default] from .semolina.toml
register("default", engine)

Use Model.query() to start building. Chain .metrics() and .dimensions() to select the fields you want, then call .execute():

query = (
    Sales.query()
    .metrics(Sales.revenue)
    .dimensions(Sales.country)
)

.execute() returns a SemolinaCursor. Use it as a context manager so the pooled connection is released when you are done, and call .fetchall_rows() to get Row objects that support both attribute and dict-style access:

with query.execute() as cursor:
    for row in cursor.fetchall_rows():
        print(row.country, row.revenue)  # attribute access
        print(row["country"])  # dict-style access

You should see output like:

US 1000
US
CA 2000
CA
US 500
US

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

semolina-0.6.0.tar.gz (51.9 kB view details)

Uploaded Source

Built Distribution

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

semolina-0.6.0-py3-none-any.whl (66.3 kB view details)

Uploaded Python 3

File details

Details for the file semolina-0.6.0.tar.gz.

File metadata

  • Download URL: semolina-0.6.0.tar.gz
  • Upload date:
  • Size: 51.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for semolina-0.6.0.tar.gz
Algorithm Hash digest
SHA256 492e6d0fe7d69dca12963fe8ba9392b63297f3746e6279885a3993aea2941207
MD5 29e1456361fa69812ec7d11263ffe852
BLAKE2b-256 d6e388d4044934a1300d25eabb594a82690f99cb4324009b229af657f0afd2ac

See more details on using hashes here.

Provenance

The following attestation bundles were made for semolina-0.6.0.tar.gz:

Publisher: release.yml on anentropic/semolina

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file semolina-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: semolina-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 66.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for semolina-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a98787485f9ce0df89c30a82c543979153c529d242bdc8f341d2cda93586bd1d
MD5 546b73400a85d4369dc0b793902d713f
BLAKE2b-256 4df03bbd821fe4b8493d049d9bb0919cb262b6282e8c5816c1e186a3dec3d42a

See more details on using hashes here.

Provenance

The following attestation bundles were made for semolina-0.6.0-py3-none-any.whl:

Publisher: release.yml on anentropic/semolina

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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