Python Engine
ZEN Engine is built as embeddable BRE for your Rust, NodeJS or Python applications.
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})
or
...
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.