This project establishes a secure connection between Qlik Sense and Python, enabling communication via the Qlik Sense Engine API. It allows you to fetch and interact with data from specified pages (such as tables and charts) in the form of hypercubes, using Python to work with Qlik Sense applications and data.
To get started, ensure you have the following prerequisites:
-
Qlik Sense Environment Access:
- You need API access to your Qlik Sense environment. (Refer to the Configuration section for details on creating certificates and a virtual proxy to establish an API connection for your user.)
- Ensure you have access to the Qlik Sense Hub with a user ID that has Root Admin permissions.
-
Python Installation:
- Python version 3.10 must be installed on your machine.
-
"Qlik Sense: call Qlik Sense Engine API with Python" by Damien Villaret
-
"Let's Dissect the Qlik Engine API" by Øystein Kolsrud:
- Clone the repository to your local machine.
- Create a virtual environment for your python program.
- Install the required dependencies:
pip install -r requirements.txt
-
Access the Certificates section in Qlik Sense QMC.
-
Create a new certificate with the following settings:
- Machine Name: Enter your local machine's name (Check via System Information on your computer).
- Certificate Password: Leave this field empty; a password is not necessary.
- Include Secret Key: Ensure this option is ticked.
- Export File Format: Select "Platform independent PEM-format".
After exporting the certificates, you need to register them on both your local machine and the Qlik Sense server:
-
Open the Microsoft Management Console (MMC) as an Administrator:
- Press
Win + R
, typemmc
, and press Enter.
- Press
-
Add the Certificates Snap-in for the Local Computer:
- Go to "File" > "Add/Remove Snap-in".
- Select "Certificates" and click "Add".
- Choose "Computer account", then "Local computer".
-
Import Certificates:
- Navigate to
Trusted Root Certification Authorities
. - Right-click, select "All Tasks" > "Import", and import the
root.pem
,client.pem
, andclient_key.pem
files. - If prompted with a warning message, select "Yes" to trust the certificates.
- Navigate to
-
Import Personal Certificates:
- Navigate to
Personal
. - Right-click, select "All Tasks" > "Import", and import the
client.pem
file.
- Navigate to
-
Create Windows Certificate:
- In Qlik Sense QMC, create a new certificate with the following setting:
- Export File Format: Select "Windows".
-
Activate Certificates on Both Machines:
- Simply run the exported certificate files by double-clicking them.
- Always select "Local Machine" during the installation process.
-
Refer to QMC, Virtual Proxies
-
Click 'Create New'
-
PROPERTIES:
- Description: Create a desired name
- Prefix: py_api
- Session Inactivity Timeout (minutes): 30
- Session Cookie Header Name: X-Qlik-Session-Api
- Anonymous Access Mode: No anonymous user
- Authentication Method: Header authentication dynamic user directory
- Header Authentication Header Name: header_user
- Header Authentication Dynamic User Directory: $ud\$id
- Add New Server Node: Add the central node to this virtual proxy
- Has Secure Attribute (https): Select
- SameSite Attribute (https): Lax
- Has Secure Attribute (http): NOT select
- SameSite Attribute (http): None
- Host Allow List: Add your IP address; if connected via VPN, add VPN IP
-
ASSOCIATED ITEMS:
- Click 'Link' and link it to the Central node.
-
- Inside your Python application, correctly reference the certificate files. The best practice is to include the certificates directly within your Python app directory and manage them securely.
- Ensure that the paths to the certificates (root, client, and client key files) are correctly specified in your application code.
- Specify the path to the PEM files to establish the secure connection.
- Engine\Settings.ini must be configured with: EnableTTL=1, SessionTTL=30
Ensure that these steps are carefully followed on both your local machine and the Qlik Sense server to establish a secure and functional API connection.
IMPORTANT NOTE:
- You need to open the app first from Qlik Sense. This action tells the engine to load the app into memory and create a session for you.
- After the app is opened and the session is established, you can run the method
EvaluateEx
using the handle returned by yourOpenDoc
call.
- Run the application to establish the API connection and perform the desired operations with Qlik Sense.
python app.py
- Refer to the Examples for usage examples.