Skip to main content
Version: 0.0.98

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.LabelRule mapping that :func:~ts_shape.eventlog.to_event_log consults.
  • :data:ts_shape.eventlog.archetypes.ARCHETYPE_BY_METHOD — the archetype classification that the coverage tests use to enforce standard_attrs completeness.

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.

Functions
NameDescription
register_lambda_ruleRegister spec in REGISTRY + ARCHETYPE_BY_METHOD; return runnable detector.
unregister_lambda_ruleRemove a rule previously installed by :func:register_lambda_rule.
load_dictsCompile and register an iterable of dict rules, all or nothing.
load_yamlLoad and register every rule under a YAML file's rules: key.

register_lambda_rule​

functionsource
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.

Parameters
NameTypeDescriptionDefault
specRuleSpecThe rule to register.required
Returns
TypeDescription
LambdaDetectorThe runnable :class:LambdaDetector.
Raises
TypeDescription
ValueErrorIf 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​

functionsource
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.

Parameters
NameTypeDescriptionDefault
class_namestrThe rule's class name.required
method_namestrThe rule's method name.required

load_dicts​

functionsource
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.

Parameters
NameTypeDescriptionDefault
entriesIterable[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
Returns
NameTypeDescription
Onelist [LambdaDetector ]class:LambdaDetector per rule, in input order.
Raises
TypeDescription
ValueErrorFor a malformed rule, a duplicate registration or an expression that does not compile (:class:UnsafeExpression).

load_yaml​

functionsource
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.

Parameters
NameTypeDescriptionDefault
pathstr | PathPath to a YAML file with a top-level rules: list.required
Returns
NameTypeDescription
Onelist [LambdaDetector ]class:LambdaDetector per rule (see :func:load_dicts).
Raises
TypeDescription
ImportErrorWhen PyYAML is not installed.
ValueErrorWhen the file has no rules: list or a rule is invalid.