Simplify Decision Logic with GoRules: An Embeddable Rules Engine for Python, Go, Rust, and NodeJS
If you've worked with JBOSS Drools or other rule engines, you're probably all too familiar with the complexity that comes with them.
Senthilnathan Karuppaiah
Use Case
If you've worked with JBOSS Drools or other rule engines, you're probably all too familiar with the complexity that comes with them. Managing decision-making logic often turns into a chore, with intricate configurations and steep learning curves.
That's why I'm excited to introduce GoRules Zen BRE—an open-source Business Rules Engine (BRE) built in Rust, designed to support Python, Go, Rust, and NodeJS. Unlike other engines like JBOSS Drools, JSON Rules Engine, or Grule, GoRules stands out for its simplicity and multi-language support, making it accessible to both developers and non-developers alike.
Why GoRules?
::list{type="success"}
- Multi-language Embeddability: Whether you're working in Python, Rust, Go, or NodeJS, you can seamlessly integrate GoRules into your projects with minimal effort.
- Rich Rules Editor: GoRules features an intuitive, graph-based decision table editor, allowing you to visualize and modify rules effortlessly. This is a significant improvement compared to the text-based editors commonly found in other engines.
- Performance: GoRules is optimized for speed, built in Rust, making it a perfect solution for large-scale applications that demand high performance.
- Ease of Use: With a much lower learning curve than other engines, GoRules is ideal for both beginners and experienced developers, making rule management more accessible than ever. ::
For more details, visit GoRules and explore the Zen Business Rules engine on GitHub.
I've also included a fully working example in a Python/Google Colab notebook. You can try it out here: Google Colab Demo. or use the below code in your favorite python editor.
!pip install zen-engine
gorules-example-ecommerce.ipynb
# Import the necessary modules
import re
import json
import zen # 'zen' is the GoRules Zen engine module for processing rules
# Load the JDM (JSON Decision Model) file
# This file contains the rules or decision logic in JSON format.
# Replace the file path with the correct one for your environment.
jdm_filename = './ecommenrce-shipping-fees.json'
# Open the JDM file in 'read' mode and load the content
with open(jdm_filename, 'r') as file:
jdm_content = file.read()
# Create a ZenEngine instance
# ZenEngine is the core engine responsible for processing your decision model.
engine = zen.ZenEngine()
# Load the decision model into the engine
decision = engine.create_decision(jdm_content)
# Define the input payload that will be processed by the decision model
# In this example, the input consists of a cart total and customer information.
input_payload = {
"cart": {
"total": 1200
},
"customer": {
"country": "US",
"tier": "gold"
}
}
# Evaluate the decision model using the provided input payload
result = decision.evaluate(input_payload)
# Output the result of the evaluation
print(result)
The decision table JSON file used in my example https://gist.github.com/senthilsweb/ec607fd16af439e76666fc77c5ecc794
Why BREs Matter
A Business Rules Engine (BRE) simplifies complex decision-making logic, which would otherwise be handled through countless if-else statements. BREs provide scalability by allowing rules to be added, modified, or removed without impacting the underlying application code. This makes them invaluable for maintaining clean, scalable, and maintainable codebases as business logic evolves over time.