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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ruleau-0.2.1.tar.gz.
File metadata
- Download URL: ruleau-0.2.1.tar.gz
- Upload date:
- Size: 18.7 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40153ce01cdf447ae01422d3ecffd8b8f284d1fbe491d16967d9c7675d233119
|
|
| MD5 |
1681dfd4aa7d5c151fae05d0d772c04c
|
|
| BLAKE2b-256 |
a5a55ca834f9974884fa56f91ce58c7878a1f91044f6efb55722d24f64ea3ca8
|
File details
Details for the file ruleau-0.2.1-py3-none-any.whl.
File metadata
- Download URL: ruleau-0.2.1-py3-none-any.whl
- Upload date:
- Size: 26.1 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f020a06755ca36dbd41454923234c387c69317fd28f1999cca727d2c67017774
|
|
| MD5 |
85c3f219999a66aa460211b4f9a8caf1
|
|
| BLAKE2b-256 |
4af584c93c747b3872be54488eb6c5a2e1e1541d4e584be57501d96ef877baa7
|