Kedro hook — attach interceptors to pipeline phases in the pipeline definition
Project description
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c63956e7fc1d209ece0a650ee1183d9d59565b32e8f6f94803362cf635098460
|
|
| MD5 |
bcefc45dbf512ae396753468017c1d6f
|
|
| BLAKE2b-256 |
9fe75ed1b9973711545dc6b904b6ea4c4900e0312114eae5a2a3400fab026c1b
|
Provenance
The following attestation bundles were made for kedro_intercept-0.0.1.tar.gz:
Publisher:
publish.yml on saemeon/kedro-intercept
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kedro_intercept-0.0.1.tar.gz -
Subject digest:
c63956e7fc1d209ece0a650ee1183d9d59565b32e8f6f94803362cf635098460 - Sigstore transparency entry: 1154503800
- Sigstore integration time:
-
Permalink:
saemeon/kedro-intercept@26fda90aef043a6e3de3f126a3c44d61a889f074 -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/saemeon
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@26fda90aef043a6e3de3f126a3c44d61a889f074 -
Trigger Event:
release
-
Statement type:
File details
Details for the file kedro_intercept-0.0.1-py3-none-any.whl.
File metadata
- Download URL: kedro_intercept-0.0.1-py3-none-any.whl
- Upload date:
- Size: 10.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1837121c1c115c198aa5faf161fb0ff9188aa9938ba02efcf29ba7e08505f477
|
|
| MD5 |
5972103f2b4fe6481a66f43bc08ef9ba
|
|
| BLAKE2b-256 |
c02bbe65aedceca81b4ed73f37b54c5fdad86955869d565055cb69a0bcd1a02d
|
Provenance
The following attestation bundles were made for kedro_intercept-0.0.1-py3-none-any.whl:
Publisher:
publish.yml on saemeon/kedro-intercept
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kedro_intercept-0.0.1-py3-none-any.whl -
Subject digest:
1837121c1c115c198aa5faf161fb0ff9188aa9938ba02efcf29ba7e08505f477 - Sigstore transparency entry: 1154503801
- Sigstore integration time:
-
Permalink:
saemeon/kedro-intercept@26fda90aef043a6e3de3f126a3c44d61a889f074 -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/saemeon
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@26fda90aef043a6e3de3f126a3c44d61a889f074 -
Trigger Event:
release
-
Statement type: