Skip to main content

Python Engine

ZEN Engine is built as embeddable BRE for your Rust, NodeJS, Go or Python applications.


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



engine = zen.ZenEngine({"loader": loader})
decision = engine.get_decision("jdm_graph1.json")
result = decision.evaluate({"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.

Evaluate expressions

You may also evaluate singular ZEN Expressions.

import zen

zen.evaluate_expression("1 + 1") # 2
zen.evaluate_expression("a + b", { "a": 10, "b": 20 }) # 30

zen.evaluate_unary_expression("> 10", { "$": 5 }) # false
zen.evaluate_unary_expression("> 10", { "$": 15 }) # true