Skip to main content

Official Support Articles

Search or browse our knowledge base to find answers to your questions ranging from account questions to troubleshooting error messages. The content is curated and updated by our global Support team

QlikWorld 2023, a live, in-person thrill ride. Save $300 before February 6: REGISTER NOW!

Qlik AutoML: How to generate predictions via API realtime-predictions with Python

Showing results for 
Search instead for 
Did you mean: 

Qlik AutoML: How to generate predictions via API realtime-predictions with Python

In a previous article, I outlined the steps to POST an API call to realtime-predictions with Postman. In this article, we will look at how to do this in Python and send a file with records to predict against.

As before, we use iris.csv dataset, a common data science example. Variety is the target variable.



  1. Upload, train and deploy the model for iris.csv.  See this article for steps on how to deploy a model. 

    XGBoost Classification was the champion model which I choose to deploy.

  2. Generate an API key. Copy this information for later steps. 

  3. Open the Deployed model and navigate to the Real-time predictions tab


  4. Copy the Realtime-predictions URL to a safe place


  5. Open a Python instance (in this case a jupyter notebook) and import the required packages.

    Set the API key and API URL as string variables.


  6. Read a local data file to a dataframe


  7. Set the proper header, json_data, and parameter values


  8. Get the response and print the result



In our example, we print response.text, but this could also have been saved as a file.  This is a powerful option for generating prediction results locally or in a location python has access to. 

Additionally, with pandas, we can send a larger amount of records (from CSV to dataframe) in one POST call rather than having manual JSON entries with Postman. 


Here is the code used above:



api_url = ''
api_key = 'xxxx'

df = pd.read_csv('C:\\tmp\\iris_pred.csv')
rows = df.to_dict('tight')['data']

headers = {
    'Authorization': 'Bearer ' + api_key,
    'Content-type': 'application/json',
    'Accept': 'text/csv',
json_data = {
    "rows": rows, 
    "schema": [
          {"name": "sepal.length"},
          {"name": "sepal.width"},
          {"name": "petal.length"},
		  {"name": "petal.width"} 
params = {
    'includeNotPredictedReason': 'false',
    'includeShap': 'true',
    'includeSource': 'false'

response =, headers=headers, json=json_data, params=params)







The information in this article is provided as-is and to be used at own discretion. Depending on tool(s) used, customization(s), and/or other factors ongoing support on the solution below may not be provided by Qlik Support.


Labels (1)
Version history
Last update:
‎2022-10-24 10:46 AM
Updated by: