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 follows:

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.2.2.tar.gz (18.8 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.2.2-py3-none-any.whl (26.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ruleau-0.2.2.tar.gz
  • Upload date:
  • Size: 18.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for ruleau-0.2.2.tar.gz
Algorithm Hash digest
SHA256 f8bd524c3e93e9486ec675857f6352c13c9d97f8d09515165959aa03c6a7fb90
MD5 9be6530736eeeeebeca740887c039967
BLAKE2b-256 2035ad39bd4df8026fb070251a606bb7ea389ba76cfff308bfde138a481f1227

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruleau-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 26.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for ruleau-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 856c88176b82f84b81ddfc17531a3178d27c8ad45115ea7ef4684ccbad26184f
MD5 ebfc3a62c99515674d24cdc7f7dd5bc1
BLAKE2b-256 b4392aff017a66d005d96b18cd4ddeec2b50e622968062f2904cb4f672102a9f

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