Python Drools SDK
This is a python package that allow you to interact with the REST API exposed by your KIE Server instance powered by Drools.
Installation
First and foremost, start by installing the package by running the following command :
pip install git+https://github.com/PapiHack/python-drools-sdk.git
Or more simply with :
pip install python-drools-sdk
Usage
Example of usage :
from python_drools_sdk.commands.insert_elements_command import InsertElementsCommand
from python_drools_sdk.commands.insert_object_command import InsertObjectCommand
from python_drools_sdk.kie.drools import Drools
from python_drools_sdk.utils import helpers
from python_drools_sdk.exceptions.drools_exception import DroolsException
# A dataclass for the example
class Person:
def __init__(self, **kwargs) -> None:
self.name = kwargs.get('name', 'Papi')
self.age = kwargs.get('age', 46)
self.id = kwargs.get('id', None)
self.isMajor = kwargs.get('isMajor', None)
def __str__(self) -> str:
return 'Person [id => {}, name => {}, age => {}, isMajor => {}]'.format(self.id, self.name, self.age, self.isMajor)
# Set configuration variables like your KIE_SERVER credentials, ROOT KIE_SERVER URL and so on
Drools.KIE_SERVER_CONTAINER_PACKAGE = 'you_kie_container_package' # Example: com.myspace.sample_project
Drools.KIE_SERVER_USERNAME = 'your_kie_server_username'
Drools.KIE_SERVER_PASSWORD = 'your_kie_server_password'
Drools.KIE_SERVER_ROOT_URL = 'your_kie_server_url'
Drools.KIE_SERVER_CONTAINER_ID = 'your_kie_container_id' # Example : Sample_Project_1.0.0-SNAPSHOT
# If you defined a KIE_SESSION in your drools workbench project, you can specify it like the following line
Drools.KIE_SESSION_NAME = 'your_kie_session_name'
# Creation of data objects
person = Person(id=1)
P1 = Person(name='Fatou', id=2, age=15)
P2 = Person(name='Daba', id=3, age=17)
P3 = Person(name='Nabou', id=4, age=28)
persons = [P1, P2, P3]
# Create an InsertObjectCommand in order to fire rules on a specific object
# The 'object' parameter represent the object to sent, 'out_identifier' should be a unique key
# that is going to used for extracting the associated object after having response from drools kie server
insert_command = InsertObjectCommand(object=person, out_identifier="person_papi").initialize()
# Create an InsertElementsCommand in order to fire rules on a list of object
# The 'objects' parameter represent the list of object to sent, 'out_identifier' should be a unique key
# that is going to used for extracting the associated objects'list after having response from drools kie server
insert_elements_command = InsertElementsCommand(objects=persons, out_identifier='persons').initialize()
# Add commands before excuting them
Drools.add_command(insert_command)
Drools.add_command(insert_elements_command)
# Execute all commands
try:
response = Drools.execute_commands()
except DroolsException as de:
print(de)
# Getting data by using the previous 'out_identifier' key
drools_person_response = response['person_papi']
# Getting the list of persons after drools rules execution on them by using its respective key
drools_persons_list_response = response['persons']
# I also make some helpers that will allow you to convert a json (dict) to a specific object and vice versa
# Here the 'json2object' function take as a first parameter the json/dict to be converted and as a final parameter,
# the destination type (here, the 'Person' class that we defined earlier)
person_papi_object = helpers.json2object(drools_person_response, Person)
print(person_papi_object)
# A function named 'object2json' is also defined and allow you like its name says, to convert an object to json/dict
Contributing
Feel free to make a PR or report an issue.
Oh, one more thing, please do not forget to put a description when you make your PR 🙂
Contributors
Metadata
Release files for python-drools-sdk 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| python-drools-sdk-0.0.3.tar.gz | 6.6 kB | Without provenance | Details for python-drools-sdk-0.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| python_drools_sdk-0.0.3-py3-none-any.whl | Python 3 | none | any | Details for python_drools_sdk-0.0.3-py3-none-any.whl |
Total release size: 15.8 kB
Release files / python-drools-sdk-0.0.3.tar.gz
| Download URL | python-drools-sdk-0.0.3.tar.gz |
|---|---|
| Size | 6.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cb84a9e38f4cb91f5ba735e41067bf6bd02c2b1fa14e2ec8ac5aadc7288f4e1c
|
|
BLAKE2b-256 checksum How to use checksums |
e9a13bc33cb24f1f9f49b30c4264d44999eb91aba838046eb93e05328cff27c8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10
|
Release files / python_drools_sdk-0.0.3-py3-none-any.whl
| Download URL | python_drools_sdk-0.0.3-py3-none-any.whl |
|---|---|
| Size | 9.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
663fd968296ff8d0366125fb7d537ec259dec551df203593f33d169bb5d9799e
|
|
BLAKE2b-256 checksum How to use checksums |
26070f59b620b4fa6599d7c2af0b006e28da1d4532ab2118391b2d7f337f8611
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10
|
Security for python-drools-sdk 0.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.