> For the complete documentation index, see [llms.txt](https://docs.hackle.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.hackle.io/en/development-guide/python.md).

# 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](https://docs.hackle.io/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.

Reuse the already-created instance for every request.

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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
