SDK Integration

This document provides steps for integrating your Python app or browser with Hackle via the Hackle SDK for Andriod platforms. SDK Integration is a must in order to use the functions of a Hackle SDK.

Step 1: Add Dependencies

Think of this step as importing our SDK into your codebase. To use our Hackle services add the following dependency code and import our SDK.

pip install hackle-sdk

Step 2: Initialize the SDK

Once you have imported the dependencies, in order to start using the Hackle SDK you must initialize the SDK. During this step, we get the information needed for SDK integration from the Hackle Server and store it in the SDK.

hackle_client is a class that provides methods for using the SDK functions.

Instantiation

from hackle import hackle

// Enter the SDK Key in the YOUR_SERVER_SDK_KEY. 
hackle_client = hackle.Client(sdk_key='YOUR_SERVER_SDK_KEY')

Instantiate hackle_client by passing the SDK key.
hackle_client periodically synchronizes with the Hackle server as a background task to constantly obtain the necessary information.

❗️

hackle_client is a global variable and must be created only once.

hackle_client manages the status internally to evaluate results directly from threads without I/O. It uses additional resources for this. Instead of creating a new instance for every request, it uses an instance that has already been created.

Since hackle_client is created as a Singleton object, it is not recreated even if used with hackle.Client() for use in other functions.

Termination

hackle_client.close()

When the application is closed, you must close the hackle_client through the hackle_client.close() method. This allows the client to release the resources it is using and send the remaining tracked events. Tracked Events may be lost if the application is terminated without this process.

▼ What if you using Flask or Django?

@atexit.register can automatically close hackle_client when the application is being closed.

import atexit

@atexit.register
def __exit__():
    hackle_client.close()

Did this page help you?