Skip to main content

Open-Source Business Rules Engine

Project description

License: MIT

Python Rules Engine (ZEN Engine)

ZEN Engine is a cross-platform, Open-Source Business Rules Engine (BRE). 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.

JSON Decision Model

An open-source React editor is available on our JDM Editor repo.


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.


pip install zen-engine


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 =

engine = zen.ZenEngine()

decision = engine.create_decision(content)
result = decision.evaluate({"input": 15})


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:

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).

An open-source version of the React Component is available on our JDM Editor repo.

You can try Free Online Editor with built-in Simulator.

JSON Example

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.


Input fields are commonly (qualified) names for example or

  "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.


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


Screenshot 2023-03-10 at 22 57 04

And the result would be:

  "flatProperty": "A",
  "output": {
    "nested": {
      "property": "B"
    "property": 36


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 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 darwin-x64 darwin-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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zen_engine-0.16.0.tar.gz (101.6 kB view hashes)

Uploaded source

Built Distributions

zen_engine-0.16.0-cp312-none-win_amd64.whl (8.5 MB view hashes)

Uploaded cp312

zen_engine-0.16.0-cp311-none-win_amd64.whl (8.5 MB view hashes)

Uploaded cp311

zen_engine-0.16.0-cp310-none-win_amd64.whl (8.5 MB view hashes)

Uploaded cp310

zen_engine-0.16.0-cp39-none-win_amd64.whl (8.5 MB view hashes)

Uploaded cp39

zen_engine-0.16.0-cp38-none-win_amd64.whl (8.5 MB view hashes)

Uploaded cp38

zen_engine-0.16.0-cp37-none-win_amd64.whl (8.5 MB view hashes)

Uploaded cp37

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page