Skip to main content

A simple rule engine implemented in python

Project description

Sauron Rule engine - One engine to rule them all

GitHub Twitter: joaovoce

A simple rule engine to be used in python, it is based on simple rules and actions that can be chained with each other. The idea is to run the rule processor on events and have it mutate data or trigger actions

Heavily inspired on FastAPI

Install

pip install sauron-rule-engine

Use it

A simple example of the usage

from sauron_rule_engine.rule_engine import RuleEngine

json_rule = """
    {
        "conditions": [
            {
                "name": "is_smaller_than",
                "arguments": {
                    "compared_to": 2
                }
            }
        ],
        "actions": [
            {
                "name": "increment_number"
            }
        ]
    }
"""
#instantiate your engine
engine = RuleEngine()

#just a dumb variable so we can see the actions in use
number_to_be_incremented = 1

@engine.condition
def is_smaller_than(compared_to: int) -> bool:
    return number_to_be_incremented < compared_to

@engine.action
def increment_number() -> None:
    nonlocal number_to_be_incremented
    number_to_be_incremented += 1

# Then just use your engine
if __name__ == "__main__":
  print(number_to_be_incremented)
  ## 1

  engine.run(json_rule)
  print(number_to_be_incremented)
  ## 2

  engine.run(json_rule)
  print(number_to_be_incremented)
  ## 2

Features coming to town

  • Exporting a json string with the conditions and actions in a given engine
  • Exported conditions and actions should include sane typing and docstring exposure
  • Support pydantic types
  • Support for choices fields with enum
  • Support for complex types with hints to the frontend (like a range for an int type

Author

👤 João Ricardo Lhullier Lugão

Show your support

Give a ⭐️ if this project helped you!


This README was generated with ❤️ by readme-md-generator

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sauron-rule-engine-0.1.5.tar.gz (4.4 kB view hashes)

Uploaded Source

Built Distribution

sauron_rule_engine-0.1.5-py3-none-any.whl (4.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page