Skip to main content

Kedro hook — attach interceptors to pipeline phases in the pipeline definition

Project description

PyPI Python License Kedro pluggy Ruff uv prek

kedro-intercept

A Kedro hook for attaching interceptors to pipeline lifecycle phases. Unlike writing a hook class, interceptors are declared in the pipeline definition — scoped to the node or dataset they belong to.

Full documentation at saemeon.github.io/kedro-intercept

Installation

pip install kedro-intercept

The hook is auto-discovered via Kedro's entry point mechanism. No settings.py changes needed.

Usage

Call intercept_node next to the node it applies to:

from kedro_intercept import intercept_node

my_node = node(func=train, inputs="raw", outputs="model", name="train_model")

intercept_node(
    my_node,
    before_node_run=log_start,
    after_dataset_saved={"model": validate_model},
)

For global phases, node can be omitted:

intercept_node(before_pipeline_run=setup, after_pipeline_run=teardown)

Or use intercept directly by phase name:

from kedro_intercept import intercept

intercept("before_pipeline_run", setup)
intercept("before_node_run", log_start, name="train_model")
intercept("after_dataset_saved", validate_model, name="model")

Parameter matching

Interceptors only need to declare the parameters they use. Everything else is dropped:

def log_start(node, run_id):
    print(f"{node.name} started — run {run_id}")

Available parameters depend on the phase. See the Kedro hooks documentation for the full signatures.

Phases

Global

Phase When
after_context_created After KedroContext is created
after_catalog_created After the data catalog is created
before_pipeline_run Before the pipeline starts
after_pipeline_run After the pipeline finishes
on_pipeline_error If the pipeline raises

Node-level

Phase When
before_node_run Before the node runs
after_node_run After the node runs
on_node_error If the node raises

Dataset-level

Phase When
before_dataset_loaded Before a dataset is loaded
after_dataset_loaded After a dataset is loaded
before_dataset_saved Before a dataset is saved
after_dataset_saved After a dataset is saved

Dataset phases accept a single callable (applied to all inputs/outputs), a list, or a dict keyed by dataset name:

intercept_node(
    my_node,
    after_dataset_saved={"predictions": validate, "metrics": log_metrics},
)

Assert variants

Every phase has an assert_ variant that re-raises on failure instead of logging a warning:

intercept_node(
    my_node,
    assert_after_dataset_saved={"predictions": check_no_nulls},
)

Logging

Kedro's default logging only covers the kedro namespace. To see output from this package, add to conf/logging.yml:

loggers:
  kedro_intercept:
    level: INFO

License

MIT

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

kedro_intercept-0.0.1.tar.gz (81.7 kB view details)

Uploaded Source

Built Distribution

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

kedro_intercept-0.0.1-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file kedro_intercept-0.0.1.tar.gz.

File metadata

  • Download URL: kedro_intercept-0.0.1.tar.gz
  • Upload date:
  • Size: 81.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for kedro_intercept-0.0.1.tar.gz
Algorithm Hash digest
SHA256 c63956e7fc1d209ece0a650ee1183d9d59565b32e8f6f94803362cf635098460
MD5 bcefc45dbf512ae396753468017c1d6f
BLAKE2b-256 9fe75ed1b9973711545dc6b904b6ea4c4900e0312114eae5a2a3400fab026c1b

See more details on using hashes here.

Provenance

The following attestation bundles were made for kedro_intercept-0.0.1.tar.gz:

Publisher: publish.yml on saemeon/kedro-intercept

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

File details

Details for the file kedro_intercept-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for kedro_intercept-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1837121c1c115c198aa5faf161fb0ff9188aa9938ba02efcf29ba7e08505f477
MD5 5972103f2b4fe6481a66f43bc08ef9ba
BLAKE2b-256 c02bbe65aedceca81b4ed73f37b54c5fdad86955869d565055cb69a0bcd1a02d

See more details on using hashes here.

Provenance

The following attestation bundles were made for kedro_intercept-0.0.1-py3-none-any.whl:

Publisher: publish.yml on saemeon/kedro-intercept

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