# Python

{% hint style="info" %}
The Hackle Python SDK supports Python 3 and above.

If you are using a WSGI environment, be sure to check the [WSGI Configuration](/en/development-guide/python/python-sdk-wsgi-init.md) guide.
{% endhint %}

## Add Dependency

[![](https://img.shields.io/pypi/v/hackle-sdk)](https://pypi.org/project/hackle-sdk)

```shell
pip install hackle-sdk
```

## SDK Initialization

{% hint style="danger" %}
`hackle_client` is a global variable and must be created only once.

`hackle_client` manages state internally to evaluate results immediately from threads without I/O.\
This uses additional resources for that purpose.

Do not create a new instance for every request; instead, use the already-created instance.

Since `hackle_client` is built as a singleton object, using `hackle.Client()` in other functions will not recreate it.
{% endhint %}

`hackle_client` is the class that provides methods for using SDK features.

To use the SDK, you need to initialize `hackle_client`.

#### Instantiation

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

* You can find the SDK Key in [SDK Integration Info](https://dashboard.hackle.io/config/sdk-setting) located inside the Hackle Service Dashboard.

```python
from hackle import hackle

# YOUR_SERVER_SDK_KEY 자리에 SDK 키를 넣습니다.
hackle_client = hackle.Client(sdk_key=YOUR_SERVER_SDK_KEY)
```

## Shutdown

When the application shuts down, you must shut down `hackle_client` using the `hackle_client.close()` method.\
This releases resources in use and sends any remaining events.

{% hint style="danger" %}
If the application shuts down without calling `hackle_client.close()`, events may be lost.
{% endhint %}

```python
hackle_client.close()
```

#### Using Flask or Django?

You can use `@atexit.register` to automatically shut down `hackle_client` when the application exits.

```python
import atexit

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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hackle.io/en/development-guide/python.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
