Skip to content

feat!: rewrite kickpython for the current Kick API (1.0.0) - #3

Merged
berkay-digital merged 7 commits into
mainfrom
dev/v1-rewrite
Nov 25, 2026
Merged

berkay-digital merged 7 commits into
mainfrom
dev/v1-rewrite

Conversation

@berkay-digital

Copy link
Copy Markdown
Owner

A rewrite of the package against Kick's current public API (https://docs.kick.com, https://api.kick.com/swagger/doc.yaml). It breaks compatibility with 0.x, so the version goes to 1.0.0. The upgrade guide is in docs/migrating.md.

Why

0.1.5 had several bugs:

  • Dead websocket chat. Kick rotated its Pusher key, so the listener stopped working.
  • Token leak. post_chat printed request headers, bearer token included.
  • Refresh crash. Token refresh called asyncio.run() inside a running event loop.
  • Logging on import. The package called logging.basicConfig() on import.
  • Bad dependency. It required the ancient PyPI asyncio package.
  • Silent errors. Failures came back as None or raw JSON instead of being raised.

What's in it

  • Endpoints. KickClient covers every non-deprecated endpoint: users, channels, chat (send, reply, delete), moderation, channel rewards and redemptions, livestreams v2, categories v2, event subscriptions, KICKs, ads and drops.
  • App tokens. The client fetches them from your credentials and renews them.
  • User tokens. as_user(user_id) refreshes them on use. Only one refresh runs per user at a time, and it survives a cancelled caller. A 401 on a valid token gets a missing-scope error instead of a pointless refresh.
  • Token stores. Memory, JSON file or SQLite. The SQLite store reads 0.x kick_tokens.db files and restricts them to owner-only.
  • Models. Every response and webhook payload has a pydantic model. Paginated endpoints return a Page with cursor support.
  • Retries. 429 responses are retried, honoring Retry-After, and so are failed GET requests.
  • WebhookHandler.
    • Checks the RSA signature, refetching Kick's key when it rotates, at most once per cooldown.
    • Rejects stale deliveries and drops duplicates.
    • Optionally accepts only listed broadcasters.
    • Parses all 10 event types and comes with an aiohttp route.
  • LiveChat. The unofficial websocket reader, clearly marked as unofficial.
    • It asks Kick for the current Pusher key at runtime.
    • One connection serves many channels.
    • It reconnects on its own, and handlers run in their own task.
  • Packaging. pyproject.toml built with hatchling, a src/ layout, py.typed, strict mypy and ruff, and CI on Python 3.10 to 3.14 plus a lowest-dependency run.
  • Docs. A new README, guides in docs/, a CHANGELOG and an AGENTS.md.

Testing

  • Offline. 87 tests against a fake in-process Kick server and a fake Pusher server. They pass on 3.10 (with the lowest direct dependencies), 3.12 and 3.14.
  • Live, app token. Channels, users, categories, livestreams with pagination, stats, the public key and introspection. The opt-in suite is pytest -m live.
  • Live, user token for berkaydigital.
    • users.me and channels.me worked.
    • Refresh rotated the token correctly.
    • Webhook subscribe, list and unsubscribe all worked.
    • Missing-scope errors were checked against real 401s.
    • Chat made a full round trip: a bot message was sent through the API, received on LiveChat, then answered with a threaded reply.
  • Spec mismatch. /public/v2/categories only accepts repeated keys, not the comma-separated lists the spec describes.
  • Not tested live. Moderation, rewards, KICKs, ads, channel updates and drops are covered by offline tests only. The app currently grants just user:read channel:read chat:write events:subscribe.

Review

Two reviews ran independently: Gemini 4 Neon for correctness and Claude Fable 5.2 for security. A Fable re-review then checked the fixes. All findings were fixed except one. Rejecting webhook bodies that don't match their known event type would also reject real deliveries if Kick changes a payload, and Kick unsubscribes endpoints that keep failing. The docs cover that limitation instead.

@berkay-digital
berkay-digital merged commit 8b9b506 into main Nov 25, 2026
8 checks passed
@berkay-digital berkay-digital linked an issue Nov 25, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Post to chat not working. Same with refresh token..

1 participant