Overview - Python Platform SDK
The Qlik Python Platform SDK is currently in a public preview. Please expect frequent updates and at times breaking changes as feedback is incorporated between releases.
Please follow the changelog for updates.
The Typescript Platform SDK version is now deprecated. Please use the qlik-api as a replacement.
The Qlik Platform SDK is a software development kit available in Python that provide easy to use interfaces to Qlik Cloud APIs for managing tenants and building data analytics applications.
With the Platform SDK, you can:
- Access the backend services of your tenants to automate tedious and repetitive tasks.
- Build web applications on top of Qlik for managing jobs to be done across your analytics landscape.
- Connect to Qlik Sense analytics applications and access data for use in embedded applications and machine learning models.
- Create and explore analytics applications programmatically using Qlik’s unique calculation engine to solve data intensive business problems.
Get started
Prerequisites
- A Qlik Cloud tenant
- Python 3.8 or greater
- Latest version of the Python SDK
Installation
To install the Python Platform SDK, just use pip
.
python3 -m pip install --upgrade qlik-sdk
Authentication
The Platform SDK supports multiple methods for authenticating to Qlik Cloud.
Using an API Key
An API key is a token representing a user in your tenant. With an API key, a user can interact with the platform programmatically with the same access privileges and context they have during interactive sessions through a web browser. Follow this guide to obtain an API key for your tenant.
Once you have an API key, you can connect your backend application to Qlik Cloud using the Platform SDK to create backend applications.
from qlik_sdk import Auth, AuthType, Config
# Authorization
# Create auth object
config = Config(
host='<QLIK_TENANT_URL>',
auth_type=AuthType.APIKey,
api_key='<API_KEY>',
)
auth = Auth(config=config)
auth.authorize()
Using Machine-to-Machine OAuth2
OAuth is a standard security protocol for authorization and delegation. It allows third party applications to access API resources without disclosing the end-user credentials.
For a step-by-step guide on how to create an OAuth client for your tenant, see Create an OAuth client.
from qlik_sdk import Auth, AuthType, Config
# Authorization
# Create auth object
config = Config(
auth_type=AuthType.OAuth2,
host='<QLIK_TENANT_URL>',
client_id='<CLIENT_ID>',
client_secret='<CLIENT_SECRET>'
)
# Authorisation
client = Auth(config=config)
client.authorize()
Interact with apps
In the following examples, the user only wants to interact with the
Apps
resource.
from qlik_sdk import Apps, AuthType, Config
apps = Apps(Config(host='<QLIK_TENANT_URL>', auth_type=AuthType.APIKey, api_key='<API_KEY>'))
# app is fetched from the REST /v1/apps/{app_id}
app = apps.get(app_id="<QLIK_APP_ID>>")
# opens a websocket connection against the Engine API and gets the app layout
with app.open():
app_info = app.get_app_layout()
Interceptor
Log requests using interceptors
from qlik_sdk import Apps, AuthType, Config
client = Auth(Config(host='<QLIK_TENANT_URL>', auth_type=AuthType.APIKey, api_key='<API_KEY>'))
user_me = client.rest(path="/users/me")
# request interceptor method
def log_req(req: requests.Request) -> requests.Request:
print(req)
return req
# registers an interceptor
client.rpc.interceptors["request"].use(log_req)
app_list = client.rest(path="/items", params={"resourceType":"app", "limit": 100})
Raw calls to backend
import sys
import uuid
from qlik_sdk import Apps, Auth, AuthType, Config
config = Config(
host="<QLIK_TENANT_URL>", auth_type=AuthType.APIKey, api_key="<API_KEY>"
)
auth = Auth(config)
apps = Apps(config)
session_app_id = "SessionApp_" + str(uuid.uuid1())
session_app = apps.create_session_app(session_app_id)
with session_app.open():
# create a generic object of a custom type
properties = {
"qInfo": {"qType": "custom-object"},
}
obj = session_app.create_session_object(properties)
# set a custom property i.e. a property not defined in GenericObjectProperties
properties["CustomProperty"] = "custom-property-value"
obj.set_properties(properties)
# fetch the properties and validate that the custom property is returned
new_props = obj.get_properties()
if new_props.qInfo.qType != "custom-object":
sys.exit(1)
if new_props.CustomProperty != "custom-property-value":
sys.exit(1)