A simple library for simple connecting to DecisionRules API
Project description
DecisionRulesPy
A simple library that allows you to easily connect to DecisionRules.io from your application.
Usage
- Solver (Rules, Compositions)
- Management API
1 - Solver
Solver is designed for solving rules made in DecisionRules application.
You can run solver with decisionrules.solver()
method. Rule ids are accessible in DecisionRules app.
1.1 - Defining solver init
Solver need some data beforehand, like api keys
from decisionrules import *
async def solver_test():
decisionrules.init(api_key)
1.2 - Defining solver method with data
Solver method expects 5 arguments
- SolverType - enum value - mandatory
- RuleId - str - mandatory
- Data - dict or json str - mandatory
- SolverStrategy - enum value - mandatory
- Version - str - optional
async def solver_test():
data = {"say": "Hello from python"}
decisionrules.init(api_key)
# SolverType enum changes type of solver (Rule or Compostion)
response = await decisionrules.solver(decisionrules.SolverType.RULE, get_rule, data, SolverStrategies.STANDARD)
response2 = await decisionrules.solver(decisionrules.SolverType.RULEFLOW, compo_rule, data, SolverStrategies.STANDARD)
1.3 Solver with custom domain
For using custom domain just add CustomDomain
instance to the init method
with url
and protocol
parameters.
async def solver_test():
data = {"say": "Hello from python"}
decisionrules.init(api_key, CustomDomain("YOUR_URL", Protocols.HTTPS))
response = await decisionrules.solver(decisionrules.SolverType.RULE, get_rule, data, SolverStrategies.STANDARD)
response2 = await decisionrules.solver(decisionrules.SolverType.COMPOSITION, compo_rule, data, SolverStrategies.STANDARD)
2 - Management API
Management api is accessible via dr_management
and required management api key that you can obtain in api key section in DecisionRules app.
Management api key is defined in custom dr_management
init
method.
async def crud_test():
dr_management.init(mng_key)
2.1 Management API usage example
from decisionrules import *
async def crud_test():
dr_management.init(mng_key)
get_rule_resp = await dr_management.get_rule_by_id(get_rule)
get_rule_by_version_resp = await dr_management.get_rule_by_id_and_version(get_rule, "1")
get_space_resp = await dr_management.get_space(get_space)
await dr_management.put_rule(put_rule, "1", put_data)
await dr_management.post_rule(post_rule, post_data)
await dr_management.delete_rule(delete_rule, "1")
2.3 All available methods in management API
- GetRuleById - Search for single rule by its ID
- GetRuleByIdAndVersion - Search for single rule by its ID and version
- GetSpace - Search for space by its ID
- PostRuleForSpace - Post new rule to the space
- PutRule - Update existing rule
- DeleteRule - Delete existing rule
dr_management.get_rule_by_id(get_rule)
dr_management.get_rule_by_id_and_version(get_rule, "1")
dr_management.get_space(get_space)
dr_management.put_rule(put_rule, "1", put_data)
dr_management.post_rule(post_rule, post_data)
dr_management.delete_rule(delete_rule, "1")
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
Hashes for decisionrulespy-2.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | db497e1062df10c5a33b86657cbfa2ebb5cc9a3acfdf8d6fbccb6c3a3f87ae7b |
|
MD5 | b22ddbd78216793c0ea9bee3ec401239 |
|
BLAKE2b-256 | 1a0817e6a1b7469579e42b86f8649907a774f40f7550f08761811c0b3d224f4f |