Rule Syntax¶
The syntax for creating rules is based off of logical expressions evaluating to either True (matching) or False (nonmatching). Rules support a small set of data types which can be defined as constants or resolved using the Python object on which the rule is being applied.
Rule Engine Data Type 
Compatible Python Types 


Not all supported operations work with all data types as noted in the table below. Rules follow a standard order of operations.
Grammar¶
The expression grammar supports a number of operations including basic arithmetic for numerical data and regular expressions for strings. Operations are type aware and will raise an exception when an incompatible type is used.
Supported Operations¶
The following table outlines all operators that can be used in Rule Engine expressions.
Operation 
Description 
Compatible Data Types 
Arithmetic Operators 


Addition 


Subtraction 


Multiplication 


Exponent 


True division 


Floor division 


Modulo 

BitwiseArithmetic Operators 


Bitwiseand ^{1} 


Bitwiseor ^{1} 


Bitwisexor ^{1} 


Bitwise right shift ^{1} 


Bitwise left shift ^{1} 

Comparison Operators 


Equal to 
ANY 

Not equal to 
ANY 
ArithmeticComparison Operators 


Greater than 


Greater than or equal to 


Less than 


Less than or equal to 

FuzzyComparison Operators 


Regex match ^{2} 


Regex search ^{2} 


Regex match fails ^{2} 


Regex search fails ^{2} 

Logical Operators 


Logical and 
ANY 

Logical not 
ANY 

Logical or 
ANY 
^{1} Bitwise operations support floating point values, but if the value is
not a natural number, an EvaluationError
will be
raised.
^{2} When using regular expression operations, the expression on the left is the string to compare and the expression on the right is the regular expression to use for either the match or search operation.
Reserved Keywords¶
The following keywords are reserved and can not be used as the names of symbols.
Keyword 
Description 

The 
Booleans ( 


The “True” boolean value 

The “False” boolean value 
Floats ( 


Floating point value for infinity 

Floating point value for notanumber 
Logical Operators 


Logical “and” operator 

Logical “not” operator 

Logical “or” operator 
Membership Operators 


Checks member is in the container 
Literal Values¶
STRING and DATETIME literal values are specified in a very similar manner by
defining the value as a string of characters enclosed in either single or double
quotes. The difference comes in an optional leading character before the opening
quote. Either no leading character or a single s
will specify a standard
STRING value, while a single d
will specify a DATETIME value.
DATETIME literals must be specified in ISO8601 format. The underlying parsing
logic is provided by dateutil.parser.isoparse()
. DATETIME values with
no time specified (e.g. d"20190923"
) will evaluate to a DATETIME of the
specified day at exactly midnight.
Example rules showing equivalent literal expressions:
"foobar" == s"foobar"
d"20190923" == d"20190923 00:00:00"
FLOAT literals may be expressed in either binary, octal, decimal, or hexadecimal
formats. The binary, octal and hexadecimal formats use the 0b
, 0o
, and
0x
prefixes respectively. Values in the decimal format require no prefix and
is the default base in which values are represented. Only base10, decimal
values may include a decimal place component.
Example rules showing equivalent literal expressions:
0b10 == 2
0o10 == 8
10.0 == 10
0x10 == 16
FLOAT literals may also be expressed in scientific notation using the letter
e
.
Example rules show equivalent literal expressions:
1E0 == 1
1e0 == 1
1.0e0 == 1
Builtin Symbols¶
The following symbols are provided by default using the
from_defaults()
method. These symbols can be accessed
through the $
prefix, e.g. $pi
. The default values can be overridden by
defining a custom subclass of Context
and setting the
builtins
attribute.
Name 
Data Type 
Value Description 
Math related 

e 
The mathematical constant e (2.71828…). 

pi 
The mathematical constant pi (3.14159…). 

Timestamp related 

now 
The current timestamp (including time)
using the default timezone from


today 
The current timestamp, (excluding time,
normalized to midnight / 00:00:00)
using the default timezone from
