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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file sauron-rule-engine-0.1.5.tar.gz.

File metadata

  • Download URL: sauron-rule-engine-0.1.5.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.16 CPython/3.6.7 Darwin/18.6.0

File hashes

Hashes for sauron-rule-engine-0.1.5.tar.gz
Algorithm Hash digest
SHA256 96ea4fe14942a9126ffa3a3ee0f1480014e9bba249976138b1e21e871c299ac5
MD5 f6b3e6ba8a5acc48735fc31a9d7d7b2d
BLAKE2b-256 6ad60a5e1916f752a241681e602d0ab2dcdb473ae7c5bccf609c75ba9d79852e

See more details on using hashes here.

File details

Details for the file sauron_rule_engine-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for sauron_rule_engine-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 644e3f889e10e02c20304f063f0b09076832cf6c12370d627c2e4188893ef720
MD5 adaa1bb119eb1f91980f01937aeb947e
BLAKE2b-256 7ce32338e573a047f849bf1d586edf713f0c58d46582ecf489a02777becc7416

See more details on using hashes here.

Supported by

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