Open-Source Business Rules Engine
Project description
Python ZEN Engine
ZEN Engine is business friendly Open-Source Business Rules Engine (BRE) to execute decision models according to the GoRules JSON Decision Model (JDM) standard. It is written in Rust and provides native bindings for NodeJS and Python. ZEN Engine allows to load and execute JSON Decision Model (JDM) from JSON files.
Usage
ZEN Engine is built as embeddable BRE for your Rust, NodeJS or Python applications. It parses JDM from JSON content. It is up to you to obtain the JSON content, e.g. from file system, database or service call.
If you are looking for a Decision-as-a-Service (DaaS) over REST, take a look at GoRules Cloud.
Installation
pip install zen-engine
Usage
To execute a simple decision you can use the code below.
import zen
# Example filesystem content, it is up to you how you obtain content
with open("./jdm_graph.json", "r") as f:
content = f.read()
engine = zen.ZenEngine()
decision = engine.create_decision(content)
result = decision.evaluate({"input": 15})
Loaders
For more advanced use cases where you want to load multiple decisions and utilise graphs you can build loaders.
import zen
def loader(key):
with open("./jdm_directory/" + key, "r") as f:
return f.read()
engine = zen.ZenEngine({"loader": loader})
result = engine.evaluate("jdm_graph1.json", {"input": 5})
When engine.evaluate is invoked it will call loader and pass a key expecting a content of the JDM decision graph.
In the case above we will assume file jdm_directory/jdm_graph1.json
exists.
Similar to this example you can also utilise loader to load from different places, for example from REST API, from S3, Database, etc.
JSON Decision Model (JDM)
JDM is a modeling standard for business decisions and business rules and is stored in a JSON format. Decision models are represented by graphs. Graphs are built using nodes and edges. Edges are used to pass the data from one node to another (left-side to right-side).
You can try Free Online Editor with built in Simulator.
Input node contains all data sent in the context, and Output node returns the data from the decision. Data flows from the Input Node towards Output Node evaluating all the Nodes in between and passing the data where nodes are connected.
Decision Tables
Decision table is a node which allows business users to easily modify and add new rules in an intuitive way using spreadsheet like interface. The structure of decision table is defined by its schema. Schema consists of inputs and outputs.
Decision tables are evaluated row by row from top to bottom, and depending on the hit policy a result is calculated.
Inputs
Input fields are commonly (qualified) names for example cart.total
or customer.country
.
{
"cart": {
"total": 1000
},
"customer": {
"country": "US"
}
}
Inputs are using business-friendly ZEN Expression Language. The language is designed to follow these principles:
- Side-effect free
- Dynamic types
- Simple syntax for broad audiences
List shows basic example of the unary tests in the Input Fields:
Input entry | Input Expression |
---|---|
"A" | the field equals "A" |
"A", "B" | the field is either "A" or "B" |
36 | the numeric value equals 36 |
< 36 | a value less than 36 |
> 36 | a value greater than 36 |
[20..39] | a value between 20 and 39 (inclusive) |
20,39 | a value either 20 or 39 |
<20, >39 | a value either less than 20 or greater than 39 |
true | the boolean value true |
false | the boolean value false |
any value, even null/undefined | |
null | the value null or undefined |
Note: For the full list please visit ZEN Expression Language.
Outputs
The result of the decisionTableNode evaluation is:
- an object if the hit policy of the decision table is FIRST and a rule matched. The structure is defined by the output fields. Qualified field names with a dot (.) inside lead to nested objects.
null
/undefined
if no rule matched in FIRST hit policy- an array of objects if the hit policy of the decision table is COLLECT (one array item for each matching rule) or empty array if no rules match
Example:
And the result would be:
{
"flatProperty": "A",
"output": {
"nested": {
"property": "B"
},
"property": 36
}
}
Functions
Function nodes are JavaScript lambdas that allow for quick and easy parsing, re-mapping or otherwise modifying the data. Inputs of the node are provided as function's arguments. Functions are executed on top of Google's V8 Engine that is built in into the ZEN Engine.
const handler = (input) => {
return input;
}
Decision
Decision is a special node whose purpose is for decision model to have an ability to call other/re-usable decision models during an execution.
Support matrix
linux-x64-gnu | linux-arm64-gnu | darvin-x64 | darvin-arm64 | win32-x64-msvc |
---|---|---|---|---|
yes | yes | yes | yes | yes |
We do not support linux-musl for now as we are relying on the GoogleV8 engine to run function blocks as isolates.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for zen_engine-0.6.1-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64ae807cc98dbb2e07fb1797a900fa34e8bd78070dd0d91a4c8e7f5b97e13a51 |
|
MD5 | aa172b30f17350a5c8cd98f859c33e3b |
|
BLAKE2b-256 | 27ba60956dc863ad6f128a99973946877863d8ac829d86ca04c4c62611c64794 |
Hashes for zen_engine-0.6.1-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cff4c45d94ab6ad4494a64b311dd49460701cb3e3f849b96b2d281d5d17b7426 |
|
MD5 | d5e0ec91757c55ef4e2113e14618751a |
|
BLAKE2b-256 | 0b30805d6da44ef64ae16cee2112c2bbbcdecca4472b9bb9970a4eaa81e71ae3 |
Hashes for zen_engine-0.6.1-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5faee3c7865c93a71bcbfc40dcfe11cc4bd4ac6bd179a98d6ea0c4fa941985b5 |
|
MD5 | be27bc11d95020552b78c1ce799755b0 |
|
BLAKE2b-256 | ff4b00fd391346c81779e8b1a73315ad874ef73690ea28ac18b99ffde31e1851 |
Hashes for zen_engine-0.6.1-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4bd7c8cf3ffe839e35b46b547ed18c4de50d18226b2250e61310ee5787302ec5 |
|
MD5 | d3c79d3c64bcf54c0d2bb4af622938b3 |
|
BLAKE2b-256 | 8528ac3aeed93404d10346ca88265472eff050f291240c2adf357215df96e0fa |
Hashes for zen_engine-0.6.1-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47d1e888d366b81429e942105617443833e001f3bf12ee62cbe75bec4d7b9427 |
|
MD5 | eeb195554d0d051cdf36c0e5a24d05ef |
|
BLAKE2b-256 | 4bd2717a0d357aa2a23c7126556d886cd71990ecb2156f52c5e089b41d6f35d2 |
Hashes for zen_engine-0.6.1-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce58864f93d7895b3f33b63ff32db0893afac1f4bbe8bbf6ca515a06f9fa26c1 |
|
MD5 | b2bf2efe3436780e7ca2343ef5dbed33 |
|
BLAKE2b-256 | 7fb76c28476f2efde0928ae0df03e81a5ff2fb48bedd510687073be008a34b3d |
Hashes for zen_engine-0.6.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff0ff7918f0b57271c2098fc9c6177125a8cbd4fd7d01056d5e8b157c40b813c |
|
MD5 | 6e8f126c4c8e51260fb478fd2da8b85d |
|
BLAKE2b-256 | 0ba3426607dda0f58b37fb6fccb2be4ed7f743242379cdc78948b5a2f9415097 |
Hashes for zen_engine-0.6.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5bc659134f08116562710f1410dd3f354a8ebd416c2264825adb0348be512c8d |
|
MD5 | cc19f9e87044eb53c6d653f0b27a7b84 |
|
BLAKE2b-256 | 554d67c11e33499597430847a26accc619ee67599f28446064e5020002278e04 |
Hashes for zen_engine-0.6.1-cp311-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67a6c3452d1e1c6ea3e3fa15216b586a1817a8cca20e5927321480bb46644dfb |
|
MD5 | 7d7a6503fe758f6f9b7f4fe49f315f1f |
|
BLAKE2b-256 | c10a95505c24d5fffca9f811cf4284c198db87666457dc1444e0e063514cf82a |
Hashes for zen_engine-0.6.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17a43a81a2e32d9e39e4d798ab0e63729a40dd5f35dafb0527e0ae14f3c81340 |
|
MD5 | 9a35bba70ab5fbed97a330138b794960 |
|
BLAKE2b-256 | f1a92a867eedb55fdea9a5a496cc4f09dbd19a8662910e936b63fa8c19cefb36 |
Hashes for zen_engine-0.6.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 098c746d804862ec322a196eee3f5c6cb9246ed5fcd17e2a26eb43f0fb8eec31 |
|
MD5 | 7d9a89c27340a5b7118ee2cad3d869c1 |
|
BLAKE2b-256 | 1f3e5d1e19733465c7a71753b2f553d96944d275dbceb233c4d597590c9075b0 |
Hashes for zen_engine-0.6.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 427bfdf619dd6637042258ff47eb4cbf92828bc78a7aed3ccb1e97481f80b83e |
|
MD5 | d7f46ca7b93eff186af23c5affeb4540 |
|
BLAKE2b-256 | 8e12d5b9b6262e67064b520625ac52308f018f0f37b8ece677582503244db6c6 |
Hashes for zen_engine-0.6.1-cp311-cp311-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9fc02fabef75a88b7802a18d8a09e8802726ec7234050a809f1ce61f10ba754d |
|
MD5 | 1b5a0e3f2206a6c5c75ec25d702b07ab |
|
BLAKE2b-256 | 77ed059d1ab7ac44e3161205bfdafea1780404de95e16e08f919b2c6a9d84adb |
Hashes for zen_engine-0.6.1-cp310-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 583e0eda1cf5c1bb3fdbbb072726182ddcf734ea511f48c512a97b89b453e903 |
|
MD5 | f06d05178dc8d33ed468ff5ef4e801b2 |
|
BLAKE2b-256 | 73b2077f9c61a9bf4aa880281ac4053537c986da6d8edf1ddcd85f7178083813 |
Hashes for zen_engine-0.6.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a64f25aaaf3f7f1847e28c7b96bf56b8522db3c6ff82278096d7559f9eedc797 |
|
MD5 | 1be90368776cfb2d459d0eb50e737a65 |
|
BLAKE2b-256 | 42bdbb4c9848ce629a8b59d38c591a258503b72e4ac9c40fc33656a0d9ddc787 |
Hashes for zen_engine-0.6.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2265c9a7830c3d0b9e24aa5dbb7bbd878f94b54c05f3c32d389b11d1fe2f6eca |
|
MD5 | e064519ea8b162ada6ead365294324b6 |
|
BLAKE2b-256 | 55abaf0259945646a8de79237b1dd0a1d62bac55f8a0c5a6b27729f4174b0703 |
Hashes for zen_engine-0.6.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ae7d0f852bdb5dcfe99b547a08cd94e88e94298d244ffb9a5b893af869bc598 |
|
MD5 | cbb76903c453c9bf7cff5cf4aa94e7e2 |
|
BLAKE2b-256 | bd4535cbc44ac1387d940cd537691e8d02354d6719bf152d15558258c86ba320 |
Hashes for zen_engine-0.6.1-cp310-cp310-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 451ac21bf7d491d108a6717e93388f1402de731cd75405a90c87571ccec65874 |
|
MD5 | 07917eb65cfaea5fe7a3bf5363489db2 |
|
BLAKE2b-256 | 85e898cab4516b9560cdaa57483406ea0bde435b98288de5286138f41eb9a1a4 |
Hashes for zen_engine-0.6.1-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83b680b4b28dd40abe0fb2b33d77c30dcf416a56006f9ddab718110e90b2eb95 |
|
MD5 | a0bfe4cfd5c6bb7df60a427813a073b2 |
|
BLAKE2b-256 | aa963218bbbf586b3a89caf9ec70290ae53c9d8dd2de91322c04a8bd71ecb177 |
Hashes for zen_engine-0.6.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc30b4603b6c0f0880ce6f76c9c6521f9f10c24ab0079548ecdea41e7a58328b |
|
MD5 | 023f6bafb44b2eb6ecf76bf771bf001b |
|
BLAKE2b-256 | 189cd4a1bc4001fa3ef100134144fa8ef786eeb0759a50a7c8f8eb0b789164ba |
Hashes for zen_engine-0.6.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1278439549fba3e6b133f2ded42a4f822c94213e75b2814a73d9354b7639ab3f |
|
MD5 | a669d74c401c3d808fe847f77af9847c |
|
BLAKE2b-256 | e41c773d3f78beea1fd285a80765db05e286cf1c21481b1b497fb280b1f5dbf6 |
Hashes for zen_engine-0.6.1-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f9dcb414dd1597059e8705e9ee41a98dff0d0b5f2fbc6c78b9c072c72bf07fa0 |
|
MD5 | 128da10f787f815521eb97dc3ded1b37 |
|
BLAKE2b-256 | ada3c768131dc6468d208fb3ee43b30da432224e169be7a87e836befe70057ef |
Hashes for zen_engine-0.6.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 069becc0cd4a77a8a01ba4e403643ede4b10f9d3f63d3bf533082c9dda0299f9 |
|
MD5 | b3c8b0dbba2098206f584054b845fac9 |
|
BLAKE2b-256 | 0df57fff59faaeb96ca6cfad05432a06d2c70377f99cfd785d763d9e94e6f365 |
Hashes for zen_engine-0.6.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e0f6b154ccc5e3e80dbb081dfe9b301f3b5fc6301b1792ce0a3c57cb8b90f49 |
|
MD5 | 9fc45de87be94f5962940e810d7c0939 |
|
BLAKE2b-256 | 4b6219ce90fca83f7a6131a3e1142c89e854b8ba0f71f3a5f867483a5a13275f |
Hashes for zen_engine-0.6.1-cp37-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e9afce70b80e14a8a8e12070abd5ac72641b1461e0d5d681331724ba855bd77 |
|
MD5 | f422f7b58ed758a4c906138f1583adcf |
|
BLAKE2b-256 | 6b65daf13b7c4bead973d8d1135f1bcdce5b64b357a2c894ed1a10e3d545a911 |
Hashes for zen_engine-0.6.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5660825e7c37d3a94cb3f24fc889fbda5d3e9e3d2fdd6a2c252f4c982d7ede25 |
|
MD5 | 8c9c82b6a071145539dc14ecac6d248d |
|
BLAKE2b-256 | 6a818afaee9f17bc986cd61c4b971ac00d0f184c9e0ec91cf728540a859f1414 |
Hashes for zen_engine-0.6.1-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2bdf728bf277c287ec945da34d2136d8776d100c57713271a8a0a102ae573f6d |
|
MD5 | ca1e51986d77342e0d8760bee887fbf0 |
|
BLAKE2b-256 | d8b0262e62280ba1b4aaf1a3c989b7fbdc36dc34f31deb4ed6b68f6f2000cea0 |