0

I have a set of rules that I need to apply on a couple of python objects and I am wondering how could I do this. The main goal would be to run my object through the set of rules and obtain which rule matched if any.

Example Objects:

class Student:
    def __init__(self):
        self.country:str
        self.name:str
        self.surname:str
        self.grade:int

class StudentsExamReport:
    def __init__(self):
        self.exam_id:str
        self.students: List[Student]

Example rule:

A rule I would like to apply would be something like "If more than 3 students have a grade lower than 4 then match".

I found CLIPS but I'm not sure if it can be used to match python objects or if it may be too overkill or AI oriented for me.

Santiago Alvarez
  • 167
  • 1
  • 12
  • Python itself does not make these things hard to express. `len(list(filter(lambda x: x.grade < 3), students)) > 3` – tripleee Nov 10 '22 at 15:50
  • Yes, but I need to store this rules somewhere and be able to update them or add new ones so they can't be hardcoded on the source code. – Santiago Alvarez Nov 10 '22 at 15:55
  • That's a line drawn on the water; writing them in a DSL just pushes the source code for them to a different language. – tripleee Nov 10 '22 at 15:57
  • not python but can be called from python using http requests. have a look at https://www.openpolicyagent.org/docs/latest/policy-language/, it can be run as a server and you can run multiple servers with different policy rules for each server. – SR3142 Nov 10 '22 at 18:36
  • Does this answer your question? [Python Rule Based Engine](https://stackoverflow.com/questions/53421492/python-rule-based-engine) – noxdafox Nov 11 '22 at 09:13

1 Answers1

0

I ended up creating my own engine as I didn't find one that suited my needs.

You can find it here: https://github.com/santalvarez/python-rule-engine

Santiago Alvarez
  • 167
  • 1
  • 12