Skip to main content

A python rules engine

Project description

Ruleau

A Python Rules Engine library

Using the library

from ruleau import execute, rule, ApiAdapter

# create a rule
@rule(rule_id="rul_1", name="Is adult")
def over_18(_, 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="ca_1280"
)
# 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 the ruleau-docs command.

The usage is as follow:

ruleau-docs [--output-dir=<argument>] filename

For example for a file of rules called rules.py run:

ruleau-docs rules.py

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.11.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.11-py3-none-any.whl (21.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ruleau-0.0.11.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.11.tar.gz
Algorithm Hash digest
SHA256 dd9b6ec82c80abf7811d08b5a6f3bba3ffac59dae35f157844d13b822a932dc2
MD5 4cf7cae24f0a10ef86b21ec3581a1f69
BLAKE2b-256 687e0105ab7d8869b8e8d9626c78ec84cc0d4a26eee23b1cdc9b2dc2cdc9f604

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruleau-0.0.11-py3-none-any.whl
  • Upload date:
  • Size: 21.1 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.11-py3-none-any.whl
Algorithm Hash digest
SHA256 1941bc97361aa519d62921cf73232d18496bc7fde684b6c9c2c7e7c98b7c9803
MD5 a81a02a03a353b5a1ac5eecea407e6a0
BLAKE2b-256 60e7c842b246e68758dd627c2ae29eef2e799ca7820b9d921d3c67ffce6c709d

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