Skip to main content

kedro-semantic-layer

PyPI version License

Define Boring Semantic Layer models on your Kedro datasets, straight from the catalog.

kedro-semantic-layer is a Kedro plugin that turns dataset metadata into semantic models: any Ibis-backed dataset annotated with dimensions, measures, or joins loads as a queryable SemanticModel instead of a raw table—in nodes, in kedro ipython, everywhere the catalog is used.

Installation

pip install kedro-semantic-layer

Or install the development version from source:

pip install "kedro-semantic-layer @ git+https://github.com/deepyaman/kedro-semantic-layer.git"

The plugin registers its hook automatically; no changes to settings.py are needed.

Quickstart

Annotate an Ibis-backed dataset in conf/base/catalog.yml:

flights:
  type: ibis.FileDataset
  filepath: data/01_raw/flights.parquet
  metadata:
    kedro-semantic-layer:
      dimensions:
        origin: _.origin
        destination:
          expr: _.destination
          description: "Destination airport code"
      measures:
        flight_count: _.count()
        avg_distance:
          expr: _.distance.mean()
          description: "Average distance of flights in miles"

Loading the dataset now returns a semantic model:

flights = catalog.load("flights")

flights.group_by("origin").aggregate("flight_count", "avg_distance").execute()

Joins

A joins: block references other catalog datasets by name (model:). The joined dataset's semantic model is built on demand when the joining dataset is loaded:

flights:
  type: ibis.FileDataset
  filepath: data/01_raw/flights.parquet
  metadata:
    kedro-semantic-layer:
      dimensions:
        origin: _.origin
      measures:
        flight_count: _.count()
      joins:
        carriers:
          model: carriers    # another catalog dataset
          type: one          # one | many | cross
          left_on: carrier
          right_on: code

carriers:
  type: ibis.FileDataset
  filepath: data/01_raw/carriers.parquet
  metadata:
    kedro-semantic-layer:
      dimensions:
        name: _.name

Joined dimensions and measures are addressed with the join alias as prefix:

flights = catalog.load("flights")

flights.group_by("carriers.name").aggregate("flight_count").execute()

Join targets without their own kedro-semantic-layer metadata are wrapped as plain semantic tables. Cyclic join definitions are rejected as soon as the catalog is created, with an error naming the cycle.

Supported metadata keys

Everything under metadata.kedro-semantic-layer follows the Boring Semantic Layer YAML format and is parsed by its from_config API:

Key Description
dimensions Name → Ibis deferred expression, or a dict with expr, description, is_entity, is_time_dimension, smallest_time_grain, metadata, …
measures Name → aggregate expression, or a dict with expr, description, metadata
calculated_measures Measures referencing other measures by name (e.g. ratios, percent of total)
filter Row filter applied to the model (e.g. _.distance > 1000)
joins Join alias → {model, type, left_on, right_on, how}, where model names another catalog dataset

How it works

On after_catalog_created, the plugin wraps the load() method of every dataset carrying kedro-semantic-layer metadata. The wrapper loads the underlying Ibis table as usual, then hands the metadata to Boring Semantic Layer's from_config, resolving any join references through the catalog. Datasets without the metadata key are untouched.

Because the wrapped load() closes over the catalog, and Ibis backend connections are not picklable, use the sequential or thread runner (not ParallelRunner) for pipelines that load semantic models—the same constraint that already applies to Ibis-backed datasets in general.

DataCatalog.load() has no caching, so a dataset joined by several others is rebuilt from scratch on every load that references it—including the underlying Ibis table, not just the semantic model. For a frequently-joined dataset (e.g. a shared dimension table), wrap it in kedro.io.CachedDataset to load it once per session. Declare metadata on the CachedDataset entry itself, not on the dataset: it wraps—the hook won't see metadata nested one level down.

Compatibility notes

The plugin only uses public Boring Semantic Layer APIs (from_config, to_semantic_table, SemanticModel, SemanticTable). On the Kedro side, it wraps load() through AbstractDataset._load_wrapper — the same mechanism Kedro itself uses to wrap dataset loading (e.g. for versioning). CI runs against the current Kedro release on Python 3.10–3.14; the test suite is what catches a Kedro release changing that mechanism.

It also imports kedro.utils._format_rich and _has_rich_handler, private helpers used only for optional rich-aware log formatting; the import is guarded, falling back to plain logging if they're unavailable. This isn't hypothetical—_format_rich existed in Kedro 0.19.8–0.19.11, was removed in 0.19.12–0.19.13, and returned in 0.19.14, all within the kedro>=0.19.7 range this plugin declares.

Example

See examples/airlines for a runnable project querying the Malloy airlines dataset, including the flights→carriers join above.

Metadata

Release files for kedro-semantic-layer 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kedro-semantic-layer 0.1.0
File Size Uploaded
kedro_semantic_layer-0.1.0.tar.gz 9.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for kedro-semantic-layer 0.1.0
File Interpreter ABI Platform
kedro_semantic_layer-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 19.7 kB

Release files / kedro_semantic_layer-0.1.0.tar.gz

Download URL kedro_semantic_layer-0.1.0.tar.gz
Size 9.1 kB
Tags Source
SHA-256 checksum
How to use checksums
800fb228faf8589f57bea162b185ed218b387fc9c8a084fd7fde1c39af1be9c1
BLAKE2b-256 checksum
How to use checksums
bcac565e22e73265bb1c272e72d81f308a1106b51f5cff8b9d74b52e09f5fc22
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","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}

Release files / kedro_semantic_layer-0.1.0-py3-none-any.whl

Download URL kedro_semantic_layer-0.1.0-py3-none-any.whl
Size 10.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5bdda5db5b3f0807bc680403c32a6999e53cee8f28aca8631225ca90bb60aa5e
BLAKE2b-256 checksum
How to use checksums
81475e211705260964471390cfa0719324d89a24d88f7108af7a642a311179a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","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}

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page