boolrule API

BoolRule

class boolrule.BoolRule(query, lazy=False)[source]

Represents a boolean expression and provides a test method to evaluate the expression and determine its truthiness.

Parameters:
  • query – A string containing the query to be evaluated
  • lazy – If True, parse the query the first time it’s tested rather than immediately. This can help with performance if you instantiate a lot of rules and only end up evaluating a small handful.
test(context=None)[source]

Test the expression against the given context and return the result.

Parameters:context – A dict context to evaluate the expression against.
Returns:True if the expression succesfully evaluated against the context, or False otherwise.

Exceptions

class boolrule.MissingVariableException[source]

Raised when an expression contains a property path that’s not supplied in the context.

class boolrule.UnknownOperatorException[source]

Raised when an expression uses an unknown operator.

This should never be thrown since the operator won’t be correctly parsed as a token by pyparsing, but it’s useful to have this hanging around for when additional operators are being added.