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, geolocation etc.
from decisionrules import *
async def solver_test():
decisionrules.init(api_key, GeoLocations.EU1)
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, GeoLocations.EU1)
# 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, GeoLocations.EU1, 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.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2354dea64e50f72cb0839921df977398a86b5468728387b1b2f902130c40db1 |
|
MD5 | 76385add1bdc771a9ad11ce575dd0287 |
|
BLAKE2b-256 | c77805e6b803aeceefd66d7ae731f1d93959f3e62829b53d088eb189530ca423 |