Qlik Sense qsAPI Client
qsAPI is a Python client library designed for interacting with Qlik Sense's QPS (Qlik Proxy Service) and QRS (Qlik Repository Service) interfaces. It simplifies common administrative and data operations within a Qlik Sense environment, providing a programmatic way to manage apps, users, security rules, and more. The current version is 2.2.0, and the library receives updates periodically, with major refactorings in its 2.1.0 release.
Common errors
-
ImportError: cannot import name 'QlikSenseAPI' from 'qsapi'
cause Attempting to import `QlikSenseAPI` directly from the top-level `qsapi` package after version 2.1.0.fixChange your import statement to `from qsapi.qsapi import QlikSenseAPI`. -
FileNotFoundError: [Errno 2] No such file or directory: '/path/to/client.pem'
cause The specified path for the Qlik Sense client certificate or key file is incorrect or the file does not exist.fixVerify the absolute paths provided for the `certificate` and `key` parameters in the `QlikSenseAPI` constructor. Ensure the files exist and are accessible. -
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://your_qlik_sense_host:4242/qrs/about
cause The authenticated user (defined by `user_directory` and `user_id` in conjunction with the certificate) lacks the necessary permissions within Qlik Sense to perform the requested operation.fixReview the security rules in Qlik Sense for the specified `user_directory` and `user_id`. Ensure the user has read/write access to the resources being queried or modified via the API.
Warnings
- breaking The package structure and import paths were refactored in version 2.1.0. The main `QlikSenseAPI` class moved from `qsapi` to `qsapi.qsapi`.
- gotcha Qlik Sense API authentication via certificates requires correct absolute paths to `client.pem` and `client_key.pem` files, and these files must have appropriate read permissions for the user running the Python script.
- gotcha The `user_directory` and `user_id` parameters are crucial for associating the certificate with a Qlik Sense user. Incorrect values can lead to 'Forbidden' (HTTP 403) or 'Unauthorized' errors even with valid certificates.
Install
-
pip install qsapi
Imports
- QlikSenseAPI
from qsapi import QlikSenseAPI
from qsapi.qsapi import QlikSenseAPI
Quickstart
import os
from qsapi.qsapi import QlikSenseAPI
# Configure Qlik Sense connection details. Use environment variables for production.
HOST = os.environ.get('QLIK_SENSE_HOST', 'your_qlik_sense_host') # e.g., 'yourserver.example.com'
CERT_PATH = os.environ.get('QLIK_SENSE_CERT_PATH', '/path/to/client.pem')
KEY_PATH = os.environ.get('QLIK_SENSE_KEY_PATH', '/path/to/client_key.pem')
USER_DIRECTORY = os.environ.get('QLIK_SENSE_USER_DIRECTORY', 'DOMAIN') # e.g., 'YOURDOMAIN'
USER_ID = os.environ.get('QLIK_SENSE_USER_ID', 'svc_api_user')
try:
# Initialize the Qlik Sense API client
qs_api = QlikSenseAPI(
host=HOST,
certificate=CERT_PATH,
key=KEY_PATH,
user_directory=USER_DIRECTORY,
user_id=USER_ID
)
# Example: Get Qlik Sense Engine Version
engine_version = qs_api.get_engine_version()
print(f"Successfully connected to Qlik Sense. Engine Version: {engine_version}")
# Example: Get a list of apps (uncomment to run)
# apps = qs_api.get_apps()
# print(f"Found {len(apps)} applications.")
# for app in apps[:2]: # Print details for the first two apps
# print(f" - App Name: {app.name}, ID: {app.id}")
except FileNotFoundError as e:
print(f"Error: Certificate or key file not found: {e}. Please ensure paths are correct.")
except Exception as e:
print(f"An unexpected error occurred: {e}")