This is a basic example in order to get started with Advanced Analytics Integration in Qlik Sense using PYTHON.
The architecture at a high-level looks like this:
With this new capability, we are now able to add syntax to a chart expression that tells Qlik Sense that particular expression should not be evaluated on the Qlik Sense server, but instead, all the information and data needed to calculate that expression should be sent via the server side extension on to the back end Python system for calculation.
After the advanced analytic calculations are completed, the data is sent back to the Qlik Sense Server and to the client for visualization.
In order to display a "Hello World" message in Qlik Sense Desktop , please do the following:
- Install Qlik Sense Desktop (June 2017 release or later).
- Make sure you have Python 3.4 (or later) installed as well as the
grpcio package. In order to install grpcio, use:
python -m pip install grpcio
SSEPlugin=<EngineName>,localhost:<port> on a new line in your Settings.ini file located at C:\Users\[user]\Qlik\Sense. For example: SSEPlugin=SSEPython,localhost:50052
- Create a Qlik Sense app with basic data. In my case, I have used Inline Load of 2 strings (Refer to the attached QVF).
- Now create a new KPI object in a Sheet. Under Measures, add - SSEPython.ScriptAggrStr('", ".join(args)' , HelloWorldData)
- You will need to write a Plugin using Python so that you can communicate between Sense & Python engine using gRPC. I have used the open-source plugin provided by Qlik in order to test this functionality. Please note that these plugins are open-source and support will not be provided for it by Qlik Support (refer to the T&C in https://github.com/qlik-oss/server-side-extension/blob/master/docs/writing_a_plugin.md)
- Run the plugin in CMD prompt, using command: python ExtensionService_helloworld.py
- You will be presented with this screen -
9. Now restart Qlik Sense desktop & open your Sense app.
10. You should the below object utilizing Python -Understanding the Python script & Function:SSEPython.ScriptAggrStr('", ".join(args)' , HelloWorldData)
Eight script functions are automatically added to the functionality of the plugin. What is needed to be covered on the plugin side to fulfill
the functionality is to implement the Script aggregate rpc function.
The syntax of these functions is -
where the Script is a Python script to be evaluated & Parameter is the data sent from Qlik's end.
Here, we use the ScriptAggrStr
function which accepts argument of type String & returns a String after an aggregation. The 'join' function in Python method returns a string, which is the concatenation of the strings in the sequence seq. The separator between elements is the string providing this method. From Qlik side, we pass a field called HelloWorldData which contains the 2 strings as we have loaded.
Hope this tutorial helps in understanding the basics of AAI and Python integration.