Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: CI

on:
push:
branches: [main]
pull_request:

permissions:
contents: read

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: astral-sh/setup-uv@v10.4.0
- run: uv run ruff check src tests examples
- run: uv run ruff format --check src tests examples
- run: uv run mypy
- run: uv run mypy --strict examples

test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python: ["3.10", "3.11", "3.12", "3.13", "3.14"]
resolution: [highest]
include:
- python: "3.10"
resolution: lowest-direct
steps:
- uses: actions/checkout@v7
- uses: astral-sh/setup-uv@v10.4.0
- run: uv run --isolated --python ${{ matrix.python }} --resolution ${{ matrix.resolution }} --group dev pytest -q

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: astral-sh/setup-uv@v10.4.0
- run: uv build
- run: uvx twine check --strict dist/*
90 changes: 17 additions & 73 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,84 +1,28 @@
# Python build artifacts
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
*.egg-info/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
*.egg
.installed.cfg
MANIFEST.in

# Project specific
kick_tokens.db
*.db
.env

# Virtual environment
.env/
.venv/
env/
venv/
ENV/

# IDE files
.idea/
.vscode/
*.swp
*.swo
.DS_Store

# Testing
.tox/
# Tooling
.pytest_cache/
.mypy_cache/
.ruff_cache/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Documentation
docs/_build/
docs/site/
htmlcov/

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
pyproject.toml
# Secrets and local state: never commit tokens
.env
*.db
kick_tokens.*
tokens.json

# Additional entries
htmlcov/
.mypy_cache/
# Editors / OS
.idea/
.vscode/
*.swp
.DS_Store
35 changes: 35 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# kickpython

Async Python client for the Kick.com public API, published on PyPI as `kickpython`.

## Layout

- `src/kickpython/client.py`: `KickClient` and one `*API` class per endpoint group.
- `src/kickpython/_http.py`: transport. Token selection, refresh with per-user locks, 401 handling (introspect, then refresh), retries, error mapping.
- `tokens.py` token model and stores, `oauth.py` PKCE and the authorize URL, `models.py` response models, `events.py` webhook payloads, `webhooks.py` verification and dispatch, `realtime.py` the unofficial Pusher chat reader.
- `tests/`: offline tests against a fake aiohttp server (`conftest.py`). `test_live.py` hits the real API and only runs with `-m live`.

## Commands

```bash
uv sync
uv run pytest
uv run ruff check src tests examples && uv run ruff format --check src tests examples
uv run mypy && uv run mypy --strict examples
KICK_CLIENT_ID=... KICK_CLIENT_SECRET=... uv run pytest -m live
```

## Rules

- Kick's spec lives at https://api.kick.com/swagger/doc.yaml, the docs at https://github.com/KickEngineering/KickDevDocs. Check both before adding or changing an endpoint, and test the change live. The spec has been wrong before: it says `/public/v2/categories` takes comma-separated lists, but the API only accepts repeated keys.
- Kick returns 401, not 403, for a valid token that lacks a scope.
- Never log or `repr()` tokens or client secrets.
- Models subclass `KickModel` (extra fields allowed). Convert Kick's `""` and `0001-01-01T00:00:00Z` to `None` with `OptionalStr` / `OptionalDatetime`.
- Don't wrap endpoints Kick marks deprecated.
- `realtime.py` is unofficial. Keep it isolated and keep the fallback Pusher key current (`DEFAULT_PUSHER_KEY`).

## Releasing

1. Bump `src/kickpython/_version.py` and add a `CHANGELOG.md` entry.
2. `uv build && uvx twine check --strict dist/*`
3. `uv publish` with a PyPI token, then tag `vX.Y.Z` and create a GitHub release.
36 changes: 36 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Changelog

## 1.0.0 (2026-11-25)

A rewrite against the current Kick API. Not compatible with 0.x; see [docs/migrating.md](docs/migrating.md).

### Added

- `KickClient` with resource groups for every public endpoint: users, channels, chat (send, reply, delete), moderation (ban, timeout, unban), channel rewards and redemptions, livestreams v2 and per-user livestreams, categories v2, event subscriptions, KICKs leaderboard, ads and drops.
- App access tokens via client credentials, fetched and renewed automatically.
- `as_user(user_id)` views with lazy token refresh, one refresh at a time per user, and a retry after a 401 from an expired or revoked token.
- Clear errors for missing scopes: on a 401, the client introspects the token and reports its scopes instead of refreshing a valid token.
- Token stores: memory, JSON file, SQLite (reads 0.x databases), or your own.
- Typed pydantic models for every response and webhook payload, with `Page` cursor pagination.
- `WebhookHandler`: RSA signature checks with rate-limited key refetching for rotation, timestamp and duplicate checks, an optional broadcaster allowlist, typed events, and an aiohttp route.
- `LiveChat`: a websocket chat reader for many channels over one connection, with reconnects and ping handling. It looks up Kick's current Pusher key at runtime. Handlers run in order in their own task, so a slow handler never stalls the connection.
- Retries for 429 (with `Retry-After`) and failed GET requests.
- The 127.0.0.1 redirect URI workaround from Kick's docs.
- Tests against a fake Kick server, opt-in live tests, CI on Python 3.10 to 3.14.

### Removed

- `KickAPI` and its methods.
- Deprecated Kick endpoints (`/public/v1/categories`, `/public/v1/livestreams`, `/public/v1/token/introspect`).
- `logging.basicConfig()` on import and `print()` calls that leaked bearer tokens.
- The `asyncio`, `websockets`, `python-dotenv` and required `curl_cffi` dependencies.

### Fixed

- The websocket chat listener, broken since Kick rotated its Pusher key.
- Token refresh inside a running event loop (0.x called `asyncio.run()` from async code).
- Token revocation now sends `token_type_hint` as RFC 7009 and Kick's API spec define it.

## 0.1.5 and earlier

See the git history.
Loading