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

# Python SDK

Install and initialize the Keewano SDK in a Python application.

Standard library only — the SDK has **no third-party runtime dependencies**. Install the package, call `initialize()` once at startup, and it begins collecting.

**Prerequisites:** a Keewano project API key (a JWT issued in the Keewano console) and Python 3.8+.

## 1. Install the package

```bash
pip install keewano-sdk
```

That is the only dependency change required.

## 2. Initialize with your API key

Unlike the mobile SDKs, there is **no auto-initialization** — a Python application has no manifest or process-launch hook to read a key from, so you call `initialize()` yourself, once, at startup:

```python
import keewano_sdk
from keewano_sdk import KeewanoConfig

keewano_sdk.initialize(KeewanoConfig(
    api_key="YOUR_KEEWANO_API_KEY",
    app_version="1.0.0",   # there is no manifest to read this from — supply it here
))
```

That is the whole setup. `initialize()` mints an anonymous install ID on first run, reports a launch burst (platform, OS, device, RAM, language), and starts a background upload thread. It is **idempotent**, safe to call from any thread, and **never raises** — a misconfiguration disables the SDK and logs, rather than propagating into your app. A blank API key leaves the SDK inert.

## 3. Run and verify

A healthy startup is **quiet**: the SDK logs only warnings and errors through the standard `logging` module, so no output means it started cleanly.

For a quick programmatic check, `get_install_id()` returns the install GUID once the SDK is running, or `None` if initialization was skipped or failed:

```python
print(keewano_sdk.get_install_id())   # a GUID string, or None if the SDK did not start
```

To confirm positively that events flow, report one yourself:

```python
keewano_sdk.report_button_click("Play")
```

Events are batched and uploaded on a background thread, and persisted to disk first — so they survive process exit and offline periods, and upload when a network is available. The data appears in your Keewano console rather than in your logs; the SDK does not log event contents.

## 4. Report your first event

Every reporting call is available both as a module-level function and as a method on the `KeewanoSDK` facade — they are the same callables. Each is safe to call from any thread and **never throws**; invalid arguments are dropped with a logged warning rather than raised.

```python
import keewano_sdk

# Associate your own user id with this install (assign once, after the user logs in).
keewano_sdk.set_user_id(1234567890)

# A progression milestone.
keewano_sdk.report_onboarding_milestone("finished_tutorial")
```

For events specific to your product beyond the built-in set, see [Custom Events Codegen](https://docs.keewano.com/sdks/custom-events-codegen.md) — it generates typed `report_enemy_killed("orc")`-style functions into your project.

## Flushing before exit

The SDK registers an `atexit` hook, so a **normal** interpreter exit flushes buffered events. Uploads are asynchronous, though, so for a short-lived script give the sender a moment, or stop it explicitly:

```python
keewano_sdk.flush()      # request an immediate upload (best-effort, asynchronous)
keewano_sdk.shutdown()   # flush and stop the background sender at a known point
```

Anything not yet uploaded stays on disk and is sent on the next run — nothing is lost either way.

***

## Full documentation

|                                                                                                            |                                                                                             |
| ---------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
| [Getting Started](https://github.com/Keewano/keewano-python-sdk/blob/main/docs/getting-started.md)         | Install, initialize, verify                                                                 |
| [Configuration](https://github.com/Keewano/keewano-python-sdk/blob/main/docs/configuration.md)             | Every `KeewanoConfig` option — consent gating, data directory, endpoint override, test mode |
| [Automatic Tracking](https://github.com/Keewano/keewano-python-sdk/blob/main/docs/automatic-tracking.md)   | What is captured with no extra code                                                         |
| [Custom Events](https://github.com/Keewano/keewano-python-sdk/blob/main/docs/custom-events.md)             | Your own typed events                                                                       |
| [Privacy and Consent](https://github.com/Keewano/keewano-python-sdk/blob/main/docs/privacy-and-consent.md) | Consent gating and PII                                                                      |
| [API Reference](https://github.com/Keewano/keewano-python-sdk/blob/main/docs/api-reference.md)             | Every reporting method, with validation rules                                               |

Source: [github.com/Keewano/keewano-python-sdk](https://github.com/Keewano/keewano-python-sdk)


---

# 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.keewano.com/sdks/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.
