Skip to main content

A simple rule engine implemented in python

Project description

Sauron Rule engine - One engine to rule them all

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

Install

pip install sauron-rule-engine

Use it

A simple example of the usage

from sauron_rule_engine.rule_engine import GenericRuleProcessor

class CounterRuleProcessor(GenericRuleProcessor):

    # CONDITIONS
    @staticmethod
    def counter_lt(value):
        return counter < value

    # ACTIONS
    @staticmethod
    def increment_counter():
        global counter
        counter += 2


counter = 0

input_rule1 = {
    "when": "event 1",
    "condition": "counter_lt",
    "value": 1,
    "action": "increment_counter",
}

if __name__ == "__main__":
    print(f"counter value: {counter}")
    processor = CounterRuleProcessor()
    processor.run(input_rule1)
    print(f"counter value: {counter}")
    processor.run(input_rule1)
    print(f"counter value: {counter}")

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.3.tar.gz (2.1 kB view hashes)

Uploaded Source

Built Distribution

sauron_rule_engine-0.1.3-py3-none-any.whl (2.2 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