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.8.2-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26d35754359fa5fbc978aefa036aa47aacf698d02ac4f3aa730b13dc0ec4bab2 |
|
MD5 | 5fae0bd4faa13853edcd32bb94ec6341 |
|
BLAKE2b-256 | a648d7a85d72867850f344b6c9a098494d74639b07ae5c8b1475d8061931de9d |
Hashes for zen_engine-0.8.2-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 989ba51e5c467e6479dc2f8d0a48a80b006e3d5bb8bc07a68565bc694b23d895 |
|
MD5 | 567b8810693f3427b5dbaec9944cdb24 |
|
BLAKE2b-256 | fa527a002bfb232a90d521ae8ada6bab16e17a6841a44e91b2a4ec6e3f3f027a |
Hashes for zen_engine-0.8.2-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd2093aa3fe05cd98055451e1a24bba7cf434780e4b80d3d31a70ef020dbb2d4 |
|
MD5 | 91109f09bf22b72422613c4e9cee3489 |
|
BLAKE2b-256 | 2ec28f9557fa0686bd438d5d87e72d5aed793d325e064c209e724305995d55f9 |
Hashes for zen_engine-0.8.2-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5cc54d4ce97b9cfd6e5621f1f2e9c33c69eb824abed59d303777d003107a7dc7 |
|
MD5 | a07da10bca7d3d4230d1dbb6dd606355 |
|
BLAKE2b-256 | d7a137fb797f1f9295f76e23f425463f34a22d51143786902e731a0c92fda6ea |
Hashes for zen_engine-0.8.2-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b3c3c98100352dd9effa207d4a3cb50508076627d25a3734248cbde1e5ca403 |
|
MD5 | a65de2e80cef2568a43096f519f7d412 |
|
BLAKE2b-256 | 609b1f52c0ca0505fbac3962f45fa2425a8849297bbf38da9ddd7a9e094f95fc |
Hashes for zen_engine-0.8.2-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 16020c81e26755706e18a824a7c97547db031c18f429f710ecf6edf83ae698c2 |
|
MD5 | c097a2b5416eb3025f20e7bb3c6b880d |
|
BLAKE2b-256 | 82c372aa28672df97c5fb5a1e54a90307f1c7dace24d325c287691b876a8c8b1 |
Hashes for zen_engine-0.8.2-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b5a7aac95bf89ad6eaf404a03cdbebed2a5bee2b57981b1b535e7a11a82f08a |
|
MD5 | 5a2ce43d9f1d1e78b43f3087bd6d6125 |
|
BLAKE2b-256 | f82ad06f826f028bfde88da5834e277bf30d0fb3529aa7c028e9d9999685b95c |
Hashes for zen_engine-0.8.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85eca85d86e103d610f878d05bae21018ef911dc2c4eebe583cb886c5de48dc1 |
|
MD5 | 8c09b44cd2ec7bbf56d802072d4c43b0 |
|
BLAKE2b-256 | 98396c415f2928bac9f644ee08e7fd0ebb5fd72dd1c6ff84feeb2be2f920a5e6 |
Hashes for zen_engine-0.8.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9bb9f45d62f4e05e9e66448d4a5341f2a70645f105e0296cc3f65ad30f205c19 |
|
MD5 | 16e0710fbd3370468f08df8dfa99539e |
|
BLAKE2b-256 | 0d50e349f52bfbcb74ec554e93bab7b05a5e7d49138639b6c828612a6c5922e4 |
Hashes for zen_engine-0.8.2-cp311-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7881a98960001fa9eede514f379cd766142a6112b56dd6f3efccc485c79ca63f |
|
MD5 | 1265c446b6cd1d4814bc650e48330abc |
|
BLAKE2b-256 | dba73230ded4759c290fc239f9251b7b227e554bf03f9475d9278634e5a5729b |
Hashes for zen_engine-0.8.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69eea8602abe90918563d88c3e1a3d23b33812d7e3b4fc2fe5203239e6332411 |
|
MD5 | 87bc6d287b717be16b352b43a40a2be8 |
|
BLAKE2b-256 | 310f76c0718338ab94a5040c5b46ddb5e834a7a0c22643aa6c8bf5b1498c55c7 |
Hashes for zen_engine-0.8.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a44946296e0c3fbe2930d0d786e72d15c489e5b69dde8c752083c355c6359d7f |
|
MD5 | d8bf564a035320674c427a048d401440 |
|
BLAKE2b-256 | b26265df0952e7c8f7934ae94184a9af3743eaf979dd040bcb859ab935e95bd8 |
Hashes for zen_engine-0.8.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3641124558971598abc8123427e571947c7852b1f33e4aaf76a45236f7a918b9 |
|
MD5 | 7c80e8d1ecb34bf3a56e5d3f4fede5d0 |
|
BLAKE2b-256 | b3501edf6206ff3624c88e951967578031c385881520bfb7f9501eca12971a50 |
Hashes for zen_engine-0.8.2-cp311-cp311-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e695f9041133fa60ea6e2198f71b6da5123fff2a270b61328dc11be6bb66fb4f |
|
MD5 | 8b453b041d7ab52ad6dfeb9795d1b0e2 |
|
BLAKE2b-256 | c3fd6ef6062c12e75fe56579d68093e412a4c8d3520b11912d2fdb0d138d4f62 |
Hashes for zen_engine-0.8.2-cp310-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 414f8bdcceea5da2b4c96ff6481122cba3038e940c11cd7f4c9a7ea0f6a856d2 |
|
MD5 | acc1e75fa88dd6d1fe9d222d8a08cd6d |
|
BLAKE2b-256 | 2974c5020def353d7a3c13aa21af8429f245ca883b4fede7abb2596348b5ae23 |
Hashes for zen_engine-0.8.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 53d41365245ee485746b3cbcfd0b3c3584ac4909acfb10ceb584f5b888572a36 |
|
MD5 | 2d6cf3cc324d21706db86c3ac6d22bfa |
|
BLAKE2b-256 | aa691f16044f88ec616df77ff5754da4785e6e624ea11e6abe39e57306faabe8 |
Hashes for zen_engine-0.8.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c1770152f8a9f21209b661472d4d8a99a31ce235f205edd3321ca324e89ddfe |
|
MD5 | dbf612c17754c6ab3d211747be253ceb |
|
BLAKE2b-256 | 539bc1d10494857da5fa72444fd0a9f71d9e1506027a5ae9de11d5a368a7d3a7 |
Hashes for zen_engine-0.8.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d7e0b9e15f39e33af4d658a0a56dc40852b217fc4a42aef263244b253fc26d18 |
|
MD5 | 7c6ca3c1546d9c43f0570bb0266c7dcd |
|
BLAKE2b-256 | 7b7c2127878c7936ab05b4547f2fe3ef105bb092366402945b93c34d988a5899 |
Hashes for zen_engine-0.8.2-cp310-cp310-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 742bcb67f01e94394d1e1baaade94d0daaaa7b01c74714b4f7fc64b5ac614972 |
|
MD5 | f14ce1e5fe23a375caca9a04e3e4febc |
|
BLAKE2b-256 | e9ee63d52328d901f4157f7eb9afd7593b3fa31191c0994bb649645e45afc3ff |
Hashes for zen_engine-0.8.2-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04e40c2260d82c8ff26d77fd0079a9e3ca51de0e380f7edf49be8709b6d3c59c |
|
MD5 | c5273306a1bd2ced6a6b80eaae62b2ba |
|
BLAKE2b-256 | 3b27c3ca09dbb44f7978dda173bfd96a4e0337fac52103831f3029ad868ea03f |
Hashes for zen_engine-0.8.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d0982e7d37dc2765ec3f2065e4ab0d9203488bbbf8bcdf64b9f3a922c3e6bb7 |
|
MD5 | 1cfa47a70662037ce9986c90fb7aecb2 |
|
BLAKE2b-256 | 477caff796f4c94ae1a5af94da8ea49c29c7ff884a2c562d29747590024265da |
Hashes for zen_engine-0.8.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | de00ba8c3560ba5f0468a31091f703ec1f90e16c1c1f4a9c9cd451840b6f52e2 |
|
MD5 | a9e97ad7513ba24a4da3c9297c530bcb |
|
BLAKE2b-256 | a18a5a71537f3865fca694ddc99443ad5e8a844a49ea7cedac81920d528e371f |
Hashes for zen_engine-0.8.2-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ff79304ac97db85d15d03a6ff1b4c60b84916104de8928f3fc960fe26edac6d |
|
MD5 | 4ea74a7dc819f84521a7841e6e27bd8d |
|
BLAKE2b-256 | 3bd514c0d9a1f97249fe23dfab7478af60bafecad24bf2df7afc2b66c45b081c |
Hashes for zen_engine-0.8.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a396f1fc8b744a9469b65ab7b3fa7eb85e79043a3769e989a5c73b0936f16be |
|
MD5 | 35f309067162701bfaf4e6da967d3324 |
|
BLAKE2b-256 | f66d89cf065c8df740e5f3132eb2170d1e007327be77b6fe4c4ce19a66a9cc3a |
Hashes for zen_engine-0.8.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c51d583543c2a708d4d5a324aa8b9d9fad0c892e349d21d6f7b9a00083dea8a |
|
MD5 | fbad5cb99d9070bac06ea5df287ce215 |
|
BLAKE2b-256 | 44f316cbf5be3e8ce488009f478a6e1f805b4ac7d080a98b3f8136bf7ebece01 |
Hashes for zen_engine-0.8.2-cp37-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77b29b5365f08a3f503ca3efc01d8eb560e23d67ee91b543700322932d76b044 |
|
MD5 | b3e6e83e832480a7571d7f9d79244556 |
|
BLAKE2b-256 | fd9d00ad53f02838d04b49221725dd5889b2c350242e4b6e182219c7c3c31b30 |
Hashes for zen_engine-0.8.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c18af8decbb06f26f84655183d4dbbe889962b31842b36e2c02b18c838942d7 |
|
MD5 | 8e44a5d3a7fb2cc2789c9137d264b618 |
|
BLAKE2b-256 | f290a53e76047587e4e3141d8d3d136c3ed99e6f2239123996830575839f2c15 |
Hashes for zen_engine-0.8.2-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | efbd35f42a7b4e1f3e784748793843fcba399d753dd76bc88f17b79e276f9a0a |
|
MD5 | 58daafc7c97a99fb190b92433cf06138 |
|
BLAKE2b-256 | 6386786b050820bb88e455cc80cf2befb2ef4551d75fba9a3315990d98a46f03 |