Functions¶
explain¶
Generate a plain English explanation of what a rule does.
from kompoz import explain
rule = is_admin | (is_active & ~is_banned)
print(explain(rule))
# Check passes if ANY of:
# * Check: is_admin
# * ALL of:
# * Check: is_active
# * NOT: is_banned
if_then_else¶
if_then_else(
condition: Combinator[T],
then_branch: Combinator[T],
else_branch: Combinator[T],
) -> Combinator[T]
Create a conditional combinator. If condition succeeds, run then_branch; otherwise run else_branch.
from kompoz import if_then_else
pricing = if_then_else(is_premium, apply_discount, charge_full_price)
ok, user = pricing.run(user)
async_if_then_else¶
async_if_then_else(
condition: AsyncCombinator[T],
then_branch: AsyncCombinator[T],
else_branch: AsyncCombinator[T],
) -> AsyncCombinator[T]
Async version of if_then_else.
parse_expression¶
Parse an expression string into a config dictionary. Used internally by Registry.load().
use_tracing¶
Context manager that enables tracing for all run() calls within the scope.
run_traced¶
run_traced(
combinator: Combinator[T],
ctx: T,
hook: TraceHook,
config: TraceConfig | None = None,
) -> tuple[bool, T]
Run a combinator with explicit tracing.
run_async_traced¶
run_async_traced(
combinator: AsyncCombinator[T],
ctx: T,
hook: TraceHook,
config: TraceConfig | None = None,
) -> tuple[bool, T]
Run an async combinator with explicit tracing.
use_cache¶
Context manager that enables caching for @cached_rule and @async_cached_rule predicates within the scope.
from kompoz import use_cache
with use_cache():
rule.run(user) # Executes
rule.run(user) # Uses cache
parallel_and¶
Create an async AND combinator that runs all children concurrently via asyncio.gather(). All children receive the same original context (not chained). Returns (all_ok, original_ctx).