API

pypagate Package

Functions

bind(obj, field_name, form)

Given an object and a field name, you can "bind" it to a Formula (or Term).

dataclass([cls, init, repr, eq, order, ...])

Add dunder methods based on the fields defined in the class.

either(form, f, g)

Creates a new function with name name that, when called, executes f when form is True and g when form is False.

evaluate(form)

Given a Term or Formula get the current value it contains.

field(*[, default, default_factory, init, ...])

Return an object to identify dataclass fields.

fire_on(form, *args, **kwargs)

Use as a decorator: If a Formula's truthiness is True, call the decorated function.

fire_on_all(law, *args, **kwargs)

Raw Evaluation: Bypasses the cache and queries the Universe directly.

fire_on_each(law, *args, **kwarg)

Use as a decorator: If some specialization of a Law's truthiness is True, call the decorated function.

fire_on_some(law, n, *args, **kwargs)

Raw Evaluation: Bypasses the cache and queries the Universe directly.

on_change(form, *args, **kwargs)

Use as a decorator: If a Formula's truthiness is True, call the decorated function.

permit(form, *args, **kwargs)

Use as a decorator: If a Formula's truthiness is True, allow the decorated function to be called, otherwise calling the decorated function does nothing.

reduce(function, iterable[, initial], /)

Apply a function of two arguments cumulatively to the items of an iterable, from left to right.

verify_all(law)

verify_any(law)

Classes

Any(*args, **kwargs)

Special type indicating an unconstrained type.

Bucket(universe, condition)

A linear-time spatial partition to restrict O(N^k) Law searches.

Callable()

Formula(_value, unary_op, ...)

A Well-Formed-Formula that consists of Term objects (i.e. variables) and operators.

Law(universe, variables, unary_op, bin_op, ...)

Number()

All numbers inherit from this class.

Term(_value, _parents, _binds, ...)

Essentially a variable that may be updated by the user.

Universe(entities)

Variable(universe, _var_count, _temp_value, ...)

product(*iterables[, repeat])

Cartesian product of input iterables.

pypagate.source Package

Functions

exec_always(source)

Use as a decorator: Every time source.listen(...) is called, evaluate this function.

exec_either(form, f, g, source)

Either executes f if form evaluates to True or g if form evaluates to False whenever source.listen(...) is called.

exec_while(form, source)

Use as a decorator: Every time source.listen(...) is called and the formula evaluates to True, execute this function.

Classes

Callable()

Formula(_value, unary_op, ...)

A Well-Formed-Formula that consists of Term objects (i.e. variables) and operators.

Number()

All numbers inherit from this class.

SourceMap(terms)

A collection of Terms (with starting values) where Terms can be updated with the listen method.

Term(_value, _parents, _binds, ...)

Essentially a variable that may be updated by the user.