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
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
ruleau-0.0.8.tar.gz
(14.6 kB
view details)
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
ruleau-0.0.8-py3-none-any.whl
(20.0 kB
view details)
File details
Details for the file ruleau-0.0.8.tar.gz.
File metadata
- Download URL: ruleau-0.0.8.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c86d8435d9d256205e2ea2ce04e49577a2fc750ddbb0535c83c686f66487bded
|
|
| MD5 |
e1811201276f617be7a6cdb1867398fd
|
|
| BLAKE2b-256 |
5903d5b09d61912e17221783daad5163b025f4b9b9fb1d1185e5c950a2335368
|
File details
Details for the file ruleau-0.0.8-py3-none-any.whl.
File metadata
- Download URL: ruleau-0.0.8-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9ea369f1fdcb99b7e0c1d81af459031db75b6ac05145aca0b99c3cf04a7df5e5
|
|
| MD5 |
cca4d8c6c064f0b9bd444a530b5fb058
|
|
| BLAKE2b-256 |
c3e73e0aa5b97ef1f3c1712b6ba6fd8aad54174ba7fc1b297459c3f42674b655
|