Skip to main content

A python rules engine

Project description

Ruleau

A Python Rules Engine library

Using the library

A username and password is required. This can be passed directly to the ApiAdapter (i.e. via the CLI) or these can be set in the environment variables.

RULEAU_USERNAME=myusername
RULEAU_PASSWORD=mypassword
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 with password and username in env
api_adapter = ApiAdapter(base_url="http://localhost:8000/")
# or pass directly to ApiAdapter:
api_adapter = ApiAdapter(base_url="http://localhost:8000/", username=myusername, password=mypassword)

# 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

Building & Testing the Library

Pre-requisites

Package requirements installed by running:

pip install -r requirements-dev.txt

Running the Tests

To run all unit tests in the project use the following command:

pytest

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.4.2.tar.gz (100.3 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.4.2-py3-none-any.whl (107.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ruleau-0.4.2.tar.gz
  • Upload date:
  • Size: 100.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.11.1 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.10

File hashes

Hashes for ruleau-0.4.2.tar.gz
Algorithm Hash digest
SHA256 96dc4116e3104b37975b6f59213824882892c55653dcdddc743909a186ae8f8b
MD5 2bfdc003dc78875030a05a29e91f690f
BLAKE2b-256 e52b79a9f1d0bd3c95748768fcac3b069d38e7850f345cb7b67a0d89127821e6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruleau-0.4.2-py3-none-any.whl
  • Upload date:
  • Size: 107.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.11.1 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.10

File hashes

Hashes for ruleau-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9ba98a7b26cb1059ddf2623465f7b3ce6f88c0ca0d3b4508c93692068222da2a
MD5 de4946c4ba65ffb26023d8d21fc70e96
BLAKE2b-256 046d58cbe3146859b5ed223823d2c167e588d404a4a5418c54cd82db999b2580

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