Skip to main content

A python rules engine

Project description

Ruleau

A Python Rules Engine library

Using the library

from ruleau import execute, rule
from ruleau.adapter import ApiAdapter

# create a rule
@rule(name="over_18")
def over_18(context, payload):
    return "age" in payload and payload["age"] >= 18

# create a payload (the answers to the rule's questions)
payload = {"age": 17}

# execute the rule against the payload
result = execute(over_18, payload)

# integrate with the backend web API
api_adapter = ApiAdapter(base_url="http://localhost:8000/")

# send the results
result = execute(
    over_18, payload, api_adapter=api_adapter, case_id_jsonpath="$.case_id"
)
# result.result will be False due to applicant being 17

# if the rule for this case is overriden in the backend
# then running again will return True

Testing Rules

Rules should be tested using doctest.

Example of these tests can be found in the Kitchen Sink example.

Generating Documentation

Documentation for the rules can be generated using docs.py

The usage is as follow:

python docs.py [--output-dir=<argument>] filename

For example using kitchen_sink

python docs.py ../examples/kitchen_sink/rules.py

Development Notes

# install pre-commit config
pre-commit install

# test individual file
python -m pytest --log-cli-level=debug tests/test_adapter.py

# full test
make format
make lint
make test

# all together
make format_lint_test

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

ruleau-0.0.9.tar.gz (14.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ruleau-0.0.9-py3-none-any.whl (20.0 kB view details)

Uploaded Python 3

File details

Details for the file ruleau-0.0.9.tar.gz.

File metadata

  • Download URL: ruleau-0.0.9.tar.gz
  • Upload date:
  • Size: 14.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5

File hashes

Hashes for ruleau-0.0.9.tar.gz
Algorithm Hash digest
SHA256 bcc6226f25b4a5413c14f759906e123e37ccdedb3c5c501e02f6f1e16b147a9d
MD5 3a0c7d7f9bfc51c5aa9888934d492c16
BLAKE2b-256 4fe75149cda11e30e0699aa8effa5da7078acd9e3998365b5077a5afc6932b6b

See more details on using hashes here.

File details

Details for the file ruleau-0.0.9-py3-none-any.whl.

File metadata

  • Download URL: ruleau-0.0.9-py3-none-any.whl
  • Upload date:
  • Size: 20.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5

File hashes

Hashes for ruleau-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 87d08adf84e47856ac9c2a428c01d8ebc47d13676e1f7e170dd4c05563c24edd
MD5 b331e205b14fa641b761a79bbeff3a08
BLAKE2b-256 5a9bd32a7bb51eb5c2e4c8fc8959b3de0bc1066f8e768a4da1afeaee7a640a5b

See more details on using hashes here.

Supported by

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