ts_shape.eventlog.lambda_rules.loader
Registration helpers + YAML/dict loaders for lambda rules.
A lambda rule lives in two places once registered:
- :data:
ts_shape.eventlog.taxonomy.REGISTRY— the :class:~ts_shape.eventlog.taxonomy.LabelRulemapping that :func:~ts_shape.eventlog.to_event_logconsults. - :data:
ts_shape.eventlog.archetypes.ARCHETYPE_BY_METHOD— the archetype classification that the coverage tests use to enforcestandard_attrscompleteness.
Both mutations happen through :func:register_lambda_rule. The
coverage test test_no_orphan_registry_entries is configured to
exempt entries whose class name starts with Lambda, so registered
lambda rules do not need a real Python class on disk.
| Name | Description |
|---|---|
register_lambda_rule | Register spec in REGISTRY + ARCHETYPE_BY_METHOD; return runnable detector. |
unregister_lambda_rule | Remove a rule previously installed by :func:register_lambda_rule. |
load_dicts | Compile and register an iterable of dict rules, all or nothing. |
load_yaml | Load and register every rule under a YAML file's rules: key. |
register_lambda_rule
register_lambda_rule(spec: RuleSpec) -> LambdaDetector
Register spec in REGISTRY + ARCHETYPE_BY_METHOD; return runnable detector.
The trigger expression is compiled here, so a bad expression fails at registration rather than at the first evaluation.
| Name | Type | Description | Default |
|---|---|---|---|
spec | RuleSpec | The rule to register. | required |
| Type | Description |
|---|---|
LambdaDetector | The runnable :class:LambdaDetector. |
| Type | Description |
|---|---|
ValueError | If the spec is malformed, the expression does not compile (:class:UnsafeExpression), the standard_attrs mapping uses unknown keys, the archetype's required keys are missing, or a rule with the same (class_name, method_name) is already registered. |
unregister_lambda_rule
unregister_lambda_rule(class_name: str, method_name: str) -> None
Remove a rule previously installed by :func:register_lambda_rule.
Used by tests to keep the global REGISTRY clean between cases. No-op if the rule was not registered. Deprecated class / method names resolve to their current names, as in the registry lookup.
| Name | Type | Description | Default |
|---|---|---|---|
class_name | str | The rule's class name. | required |
method_name | str | The rule's method name. | required |
load_dicts
load_dicts(entries: Iterable[Mapping[str, Any]]) -> list[LambdaDetector]
Compile and register an iterable of dict rules, all or nothing.
Every rule is validated and its trigger compiled before any is registered; if one fails, the rules registered by this call are removed again and the error is raised.
| Name | Type | Description | Default |
|---|---|---|---|
entries | Iterable[Mapping[str, Any]] | Rule mappings with the :class:RuleSpec fields; trigger is a mapping with expression (and optional min_duration_s, group_by -- a column name or a list of them). | required |
| Name | Type | Description |
|---|---|---|
One | list [LambdaDetector ] | class:LambdaDetector per rule, in input order. |
| Type | Description |
|---|---|
ValueError | For a malformed rule, a duplicate registration or an expression that does not compile (:class:UnsafeExpression). |
load_yaml
load_yaml(path: str | Path) -> list[LambdaDetector]
Load and register every rule under a YAML file's rules: key.
YAML is imported lazily so :mod:ts_shape.eventlog does not gain a
hard runtime dependency on PyYAML for users who only use built-in
detectors. Install ts-shape[yaml] to enable this loader, or use
:func:load_dicts with a hand-built list.
| Name | Type | Description | Default |
|---|---|---|---|
path | str | Path | Path to a YAML file with a top-level rules: list. | required |
| Name | Type | Description |
|---|---|---|
One | list [LambdaDetector ] | class:LambdaDetector per rule (see :func:load_dicts). |
| Type | Description |
|---|---|
ImportError | When PyYAML is not installed. |
ValueError | When the file has no rules: list or a rule is invalid. |