This project is a Simple Rule Engine application built using Python. It allows you to create, combine, and evaluate rules based on a predefined dataset. The application includes a Flask REST API and a Tkinter-based GUI, offering both a programmatic and graphical way to manage the rules. A Flask API for managing and evaluating rules. 2. A Tkinter GUI for user interaction to create, combine, and evaluate rules in a visually friendly interface.
- Python: The core programming language used.
- Flask: For serving the API endpoints.
- Tkinter: For building the desktop GUI interface.
- Threading: To run Flask and Tkinter concurrently.
- SimpleDialog: For creating input prompts in the Tkinter GUI.
- You can define custom rules as simple conditional expressions using comparison operators (
>,<,>=,<=,==). - Rules can be created using both the GUI and via the REST API.
- Example of a rule:
age > 30 AND salary > 50000
- Multiple rules can be combined using logical operators (
AND,OR). - Combined rules can also be created through both the GUI and API.
- Example: Combining rules like
age > 30andsalary > 50000usingAND.
- Rules can be evaluated against a predefined dataset, returning whether the rule conditions hold true for the dataset.
- Both individual and combined rules can be evaluated.
- The application provides a REST API via Flask, making it accessible for programmatic interactions.
- A Tkinter-based graphical interface allows users to create, combine, and evaluate rules without needing to interact with the API directly.
The Tkinter-based GUI allows you to perform the following actions:
- Create Rule: Enter a rule name and a condition to define a new rule.
- Combine Rules: Combine existing rules using logical operators.
- Evaluate Rule: Select a rule from the list and evaluate it against the predefined dataset.
- View Available Rules: The list of created rules is displayed in the GUI for easy access.
- The GUI has an intuitive layout with buttons for creating, combining, and evaluating rules.
- The Listbox in the GUI displays all available rules, which are updated dynamically as new rules are created.
- You can interact with the GUI without needing to interact with the API directly.
The rules created in the application are evaluated against the following sample dataset:
{
"age": 35,
"department": "Sales",
"salary": 60000,
"experience": 3
}- Endpoint: /api/create_rule
- Method: POST
- Request Body:
{
"name": "rule_name",
"rule": "age > 30 AND salary > 50000"
}- Success: {"message": "Rule 'rule_name' created!"}
- Error: {"error": "Invalid input"}
- Endpoint: /api/combine_rules
- Method: POST
- Request Body:
{
"name": "combined_rule_name",
"rules": ["rule1", "rule2"],
"operator": "AND"
}- Success: {"message": "Combined rule 'combined_rule_name' created!"}
- Error: {"error": "Invalid input"}
- Endpoint: /api/evaluate_rule
- Method: POST
- Request Body:
{
"name": "rule_name"
}- Success: {"result": true/false}
- Error: {"error": "Rule 'rule_name' does not exist."}
Ensure you have Python installed. Install the required packages using the following command:
pip install -r requirements.txtStart the application using the following command:
python app.pyThis will start both the Flask API (running on port 5000) and the Tkinter GUI.
The API will be available at http://localhost:5000. You can use tools like Postman or cURL to interact with it.
A Tkinter window will pop up, where you can create, combine, and evaluate rules.
- Creating Rules: You can create rules using operands (like age > 30) and logical operators (AND, OR).
- Combining Rules: Multiple rules can be combined to form complex logic.
- Evaluating Rules: The rules are evaluated against a predefined dataset using the conditions provided.
- Rules are saved to rules.json automatically on application exit.
- Rules are loaded on application startup, so you can resume where you left off.
- Combine multiple existing rules using AND or OR operators to create more complex rules.
- Use the Flask API to create, evaluate, and manage rules remotely.
- A button in the GUI and an endpoint in the API to clear all rules at once.
- A button in the GUI and an endpoint in the API to delete a specific rule by its name.