Metadata-Version: 2.4
Name: kicksdk-py
Version: 0.4.0b2
Classifier: Programming Language :: Rust
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Typing :: Typed
Requires-Dist: httpx>=0.27 ; extra == 'aio'
Requires-Dist: websockets>=13 ; extra == 'aio'
Provides-Extra: aio
License-File: LICENSE-MIT
License-File: LICENSE-APACHE
Summary: Kick (kick.com) without the I/O: requests, parsers, the realtime chat protocol and webhook verification, from one Rust core
Keywords: kick,chat,streaming,centrifugo
License-Expression: MIT OR Apache-2.0
Requires-Python: >=3.9
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Repository, https://github.com/AnisAbdellatif/kicksdk

# kicksdk (Python)

Kick (kick.com) without the I/O: requests, response parsers, the realtime chat
protocol and webhook verification, from the
[kicksdk](https://github.com/AnisAbdellatif/kicksdk) Rust core.

```bash
pip install kicksdk-py          # the core
pip install "kicksdk-py[aio]"   # plus connect_chat over asyncio (httpx, websockets)
```

The import is `kicksdk`. (On PyPI the name is `kicksdk-py`: PyPI treats
`kicksdk` as too close to the unrelated `kick-sdk`.)

```python
import asyncio, kicksdk.aio

async def main():
    async with kicksdk.aio.connect_chat(chatroom_id, channel_id) as chat:
        async for e in chat:
            ev = e["event"]
            if ev["type"] == "chat_message":
                print(ev["sender"]["username"], ev["content"])

asyncio.run(main())
```

`connect_chat` reconnects by itself until the `async with` block ends, which
closes the socket normally. After network errors, 5xx answers and dropped
sockets it waits a jittered backoff (1 s doubling to 30 s); when Kick refuses
the client (a ban, a refused token, a terminal close code), or after
`max_refusals` (5) refused attempts in a row (a 403, say), it waits 5 minutes
or more (10, 20, then 30 for more in a row) and comes back as a new client.
Only an unexpected error (a bug) ends it early, raised by the `async for`.
`chat.last_drop` says why the last connection ended and how long the wait
is, `chat.retrying` whether it is waiting now, and the `kicksdk.aio` logger
reports each drop. A failed token refresh keeps
the connection. Events the consumer has not read wait in a buffer of
`max_queue` (10,000); when it is full, `overflow="drop_oldest"` (the
default) drops the oldest and counts them in `chat.dropped`, and
`overflow="backpressure"` stops reading the socket until there is room. The
`kicksdk.aio` module docs have the details.

Everything else returns `kicksdk.Request` objects for any HTTP client and
parses what comes back (`kicksdk.website.channel_request` /
`parse_channel`, `kicksdk.public_api.livestreams_requests`,
`kicksdk.webhooks.verify`, …). Errors are `kicksdk.KickError` with `kind` and
`status`.

`kicksdk.webhooks.verify(public_key_pem, headers, body)` takes the body as
received (`bytes`, or `str`) and refuses a delivery more than 5 minutes from
now (`now=` in Unix seconds, `tolerance_secs=`), so an old one cannot be
replayed; `skip_freshness=True` re-checks a stored one.

## Every followed channel

`kicksdk.aio.fetch_all_followed(session)` retrieves every followed channel for
the viewer. Pages are requested sequentially at 5 channels per page (e.g. 49
channels = 10 requests) and deduplicated. The `session_token` is a full-account
credential: never log it.

```python
import asyncio, kicksdk.aio

async def main():
    channels = await kicksdk.aio.fetch_all_followed("session_token")
    for c in channels:
        print(c["slug"], c["live"])

asyncio.run(main())
```

## Search channels
`kicksdk.website.search_request(query)` finds channels by name on kick.com (no
login; Kick wants at least 3 characters and returns up to 20). Unofficial, so
it can change.

```py
import httpx
from kicksdk import website

req = website.search_request("xqc")
res = httpx.request(req.method, req.url, headers=req.headers)
for c in website.parse_search(res.status_code, res.text):
    print(c["slug"], c["username"], c["live"], c["followers_count"])
```

## Chat rules
`kicksdk.website.chatroom_settings_request(slug)` reads a channel's chat rules
(no login): slow mode in seconds, followers-only and minimum account age in
minutes (`None` when off), subscribers- and emotes-only. Unofficial, so it can
change.

```py
req = website.chatroom_settings_request("xqc")
res = httpx.request(req.method, req.url, headers=req.headers)
s = website.parse_chatroom_settings(res.status_code, res.text)
print(s["chatroom_id"], s["slow_mode"], s["followers_only"], s["account_age"])
```

## Current viewers
`kicksdk.website.current_viewers_request(livestream_ids)` finds the viewers of up to 10 live streams by livestream id
(`WebsiteChannel.livestream_id`) in one call, no login. Unknown or ended streams
are left out. Unofficial, so it can change.

```py
req = website.current_viewers_request([140936442, 140966175])
res = httpx.request(req.method, req.url, headers=req.headers)
for s in website.parse_current_viewers(res.status_code, res.text):
    print(s["livestream_id"], s["viewers"])
```

## Follow a channel

`website.follow_request` follows a channel as the signed-in viewer and `website.unfollow_request` unfollows it
(`session_token` needed; read the answer with `website.parse_action`). Unverified: taken from a
community list and never recorded against Kick.

```py
req = website.follow_request(session_token, "xqc")
```

Wheels are built for Linux, macOS and Windows (CPython 3.9+, one abi3 wheel
per platform). Anywhere else pip builds from the source distribution, which
needs a Rust toolchain.

Kick's realtime server only accepts `Origin: https://kick.com`; `connect_chat`
sends it. MIT OR Apache-2.0. Not affiliated with Kick.

## Live API coverage

The shared core was checked against Kick on 2026-11-15: OAuth code exchange
with PKCE, refresh/revocation/introspection, app and user reads, chat
send/reply/delete, timeout/ban/unban and reward create/update/delete.
Bot send returned 404; channel editing was skipped because no original title
was available to restore. Ad breaks, enrollment, drops and redemption
accept/reject remain documentation-based. See the repository `docs/KICK.md`
and `fixtures/{public_api,id}/README.md` for evidence and limits.

Check granted OAuth scopes before protected calls: Kick can grant fewer than
requested. Never log tokens, client secrets, authorization codes, PKCE
verifiers or requests carrying them.

