Zen Engine

0.54.0 · active · verified Fri Apr 17

Zen Engine is an open-source business rules engine implemented in Rust with Python bindings, designed for high-performance decision-making. It allows users to define complex business logic using a DMN-like JSON/YAML schema for decisions and flows. As of version 0.54.0, it leverages a Rust core for efficiency and provides a Pythonic interface for integration. It is actively maintained with frequent updates.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `ZenEngine`, define a basic decision rule using its JSON schema, and evaluate it with input context. It also shows how to access the result from the `ZenResult` object.

from zen_engine import ZenEngine

# Define a simple decision rule in DMN-like JSON format
decision_rule = {
    "name": "Welcome Message Decision",
    "kind": "Decision",
    "version": 1,
    "inputs": {
        "name": "text"
    },
    "output": "text",
    "expressions": [
        {
            "kind": "Literal",
            "content": "'Hello, ' + name + '!'"
        }
    ]
}

# Initialize the Zen Engine
engine = ZenEngine()

# Evaluate the decision with context data
context = {"name": "World"}
result = engine.evaluate(decision_rule, context)

# Access the result using the ZenResult object
if result.success:
    print(f"Decision Result: {result.result}")
else:
    print(f"Decision Error: {result.error}")

# Example with a different name
context_2 = {"name": "Alice"}
result_2 = engine.evaluate(decision_rule, context_2)
print(f"Decision Result for Alice: {result_2.result}")

view raw JSON →