This article focuses on executing a Decision Model and Notation (DMN) decision model deployed on-premises FlexRule Server as a REST API Service using Python.
We going to use the Standard Loan Origination DMN sample project for this use case as well. You can simply load your DMN file into FlexRule Designer and then its ready to deploy to FlexRule Server. You can refer to this article on how to deploy a model to FlexRule Server if you have not completed that step yet.
Understanding the FlexRule Server DMN endpoint
When you deploy a DMN model to FlexRule Server, it exposes your Decisions as a REST API Service. The structure of the execute URL uses your server address and execution port.
After successfully deploying the DMN model via FlexRule Designer you will get the Execute URL as follows.

Building the Python client to execute the DMN Service on-premises
The deployed DMN service behaves like a regular REST API. Then you can write a simple Python client using requests to send the inputs and read the response.
Define the endpoint and payload
Use the execute URL from FlexRule Designer, because it includes the code query parameter for the authentication purpose. Then build an inputs array with each array element followed by name, value pair required by your DMN model . In this example we have 3 input nodes which are “Bureau data”, “Applicant data” and “Requested product”.
import requests
import json
url = "http://localhost:9001/api/services/execute/DMNLoanOrigination/1/DRD for Decide routing decision point/1?code=4F5EAF2A62EC5E54DBFDE8C737B3EB26F0085C492F6BB392B2AB1327AACF37F8&formatter=Object"
payload = {
"inputs": [
{
"name": "Bureau data",
"value": {
"Bankrupt": False,
"CreditScore": 200
}
},
{
"name": "Applicant data",
"value": {
"Age": 32,
"MaritalStatus": "S",
"EmploymentStatus": "UNEMPLOYED",
"ExistingCustomer": False,
"Monthly": {
"Income": 651000,
"Repayments": 10000,
"Expenses": 36000
}
}
},
{
"name": "Requested product",
"value": {
"ProductType": "STANDARD LOAN",
"Rate": 2.5,
"Term": 25,
"Amount": 10000
}
}
]
}
headers = {
"Content-Type": "application/json"
}
Sending the request and handling the response
Next, inside the same script, send the POST request and inspect the response. The service response contains an outputs array with your decision results.
try:
response = requests.post(url, json=payload, headers=headers)
try:
print(json.dumps(response.json(), indent=2))
except ValueError:
print(response.text)
except requests.exceptions.RequestException as e:
print("Request failed:", e)
Let's run this python script from the command line.

After successfully running the python script, we got the above JSON response for the loan origination DMN model according to the given input data. It contains an outputs array with the output parameters defined inside the model. In this case its a parameter called “Routing” and its value is “REFER”.
Summary
This article shows how to call a DMN service deployed to the FlexRule Server as a REST API services inside your own infrastructure via simple python script. It explains the structure of the execution URL, the JSON inputs structure and how to send the requests and handle the response. FlexRule Server lets you package, deploy, and expose DMN models as REST API services inside your own infrastructure, and then your Python code can simply calls them via HTTP.

