kickpython 0.1.5__tar.gz → 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- kickpython-1.0.0/.gitignore +28 -0
- kickpython-1.0.0/CHANGELOG.md +36 -0
- kickpython-1.0.0/PKG-INFO +233 -0
- kickpython-1.0.0/README.md +198 -0
- kickpython-1.0.0/docs/api.md +117 -0
- kickpython-1.0.0/docs/authentication.md +129 -0
- kickpython-1.0.0/docs/live-chat.md +65 -0
- kickpython-1.0.0/docs/migrating.md +32 -0
- kickpython-1.0.0/docs/webhooks.md +109 -0
- kickpython-1.0.0/examples/authorize.py +91 -0
- kickpython-1.0.0/examples/chat_bot.py +53 -0
- kickpython-1.0.0/examples/public_data.py +37 -0
- kickpython-1.0.0/examples/webhook_bot.py +75 -0
- kickpython-1.0.0/pyproject.toml +90 -0
- kickpython-1.0.0/src/kickpython/__init__.py +125 -0
- kickpython-1.0.0/src/kickpython/_http.py +452 -0
- kickpython-1.0.0/src/kickpython/_version.py +1 -0
- kickpython-1.0.0/src/kickpython/client.py +936 -0
- kickpython-1.0.0/src/kickpython/errors.py +115 -0
- kickpython-1.0.0/src/kickpython/events.py +257 -0
- kickpython-1.0.0/src/kickpython/models.py +401 -0
- kickpython-1.0.0/src/kickpython/oauth.py +93 -0
- kickpython-1.0.0/src/kickpython/realtime.py +661 -0
- kickpython-1.0.0/src/kickpython/scopes.py +54 -0
- kickpython-1.0.0/src/kickpython/tokens.py +349 -0
- kickpython-1.0.0/src/kickpython/webhooks.py +457 -0
- kickpython-1.0.0/tests/__init__.py +0 -0
- kickpython-1.0.0/tests/conftest.py +127 -0
- kickpython-1.0.0/tests/samples.py +153 -0
- kickpython-1.0.0/tests/test_client.py +686 -0
- kickpython-1.0.0/tests/test_live.py +72 -0
- kickpython-1.0.0/tests/test_oauth_tokens.py +206 -0
- kickpython-1.0.0/tests/test_realtime.py +235 -0
- kickpython-1.0.0/tests/test_webhooks.py +302 -0
- kickpython-0.1.5/.gitignore +0 -84
- kickpython-0.1.5/MANIFEST.in +0 -9
- kickpython-0.1.5/PKG-INFO +0 -196
- kickpython-0.1.5/README.md +0 -177
- kickpython-0.1.5/docs/README.md +0 -63
- kickpython-0.1.5/docs/auth.md +0 -102
- kickpython-0.1.5/docs/channels.md +0 -97
- kickpython-0.1.5/docs/chat.md +0 -106
- kickpython-0.1.5/docs/configuration.md +0 -85
- kickpython-0.1.5/kickpython/__init__.py +0 -9
- kickpython-0.1.5/kickpython/api.py +0 -853
- kickpython-0.1.5/kickpython/examples/listen_all_channels.py +0 -89
- kickpython-0.1.5/kickpython/examples/oauth.py +0 -200
- kickpython-0.1.5/kickpython.egg-info/PKG-INFO +0 -196
- kickpython-0.1.5/kickpython.egg-info/SOURCES.txt +0 -22
- kickpython-0.1.5/kickpython.egg-info/dependency_links.txt +0 -1
- kickpython-0.1.5/kickpython.egg-info/top_level.txt +0 -1
- kickpython-0.1.5/pyproject.toml +0 -43
- kickpython-0.1.5/requirements-dev.txt +0 -9
- kickpython-0.1.5/requirements.txt +0 -5
- kickpython-0.1.5/setup.cfg +0 -4
- kickpython-0.1.5/setup.py +0 -39
- {kickpython-0.1.5 → kickpython-1.0.0}/LICENSE +0 -0
- {kickpython-0.1.5 → kickpython-1.0.0/src}/kickpython/py.typed +0 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*.egg-info/
|
|
5
|
+
build/
|
|
6
|
+
dist/
|
|
7
|
+
.venv/
|
|
8
|
+
venv/
|
|
9
|
+
|
|
10
|
+
# Tooling
|
|
11
|
+
.pytest_cache/
|
|
12
|
+
.mypy_cache/
|
|
13
|
+
.ruff_cache/
|
|
14
|
+
.coverage
|
|
15
|
+
coverage.xml
|
|
16
|
+
htmlcov/
|
|
17
|
+
|
|
18
|
+
# Secrets and local state: never commit tokens
|
|
19
|
+
.env
|
|
20
|
+
*.db
|
|
21
|
+
kick_tokens.*
|
|
22
|
+
tokens.json
|
|
23
|
+
|
|
24
|
+
# Editors / OS
|
|
25
|
+
.idea/
|
|
26
|
+
.vscode/
|
|
27
|
+
*.swp
|
|
28
|
+
.DS_Store
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 1.0.0 (2026-11-25)
|
|
4
|
+
|
|
5
|
+
A rewrite against the current Kick API. Not compatible with 0.x; see [docs/migrating.md](docs/migrating.md).
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- `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.
|
|
10
|
+
- App access tokens via client credentials, fetched and renewed automatically.
|
|
11
|
+
- `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.
|
|
12
|
+
- Clear errors for missing scopes: on a 401, the client introspects the token and reports its scopes instead of refreshing a valid token.
|
|
13
|
+
- Token stores: memory, JSON file, SQLite (reads 0.x databases), or your own.
|
|
14
|
+
- Typed pydantic models for every response and webhook payload, with `Page` cursor pagination.
|
|
15
|
+
- `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.
|
|
16
|
+
- `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.
|
|
17
|
+
- Retries for 429 (with `Retry-After`) and failed GET requests.
|
|
18
|
+
- The 127.0.0.1 redirect URI workaround from Kick's docs.
|
|
19
|
+
- Tests against a fake Kick server, opt-in live tests, CI on Python 3.10 to 3.14.
|
|
20
|
+
|
|
21
|
+
### Removed
|
|
22
|
+
|
|
23
|
+
- `KickAPI` and its methods.
|
|
24
|
+
- Deprecated Kick endpoints (`/public/v1/categories`, `/public/v1/livestreams`, `/public/v1/token/introspect`).
|
|
25
|
+
- `logging.basicConfig()` on import and `print()` calls that leaked bearer tokens.
|
|
26
|
+
- The `asyncio`, `websockets`, `python-dotenv` and required `curl_cffi` dependencies.
|
|
27
|
+
|
|
28
|
+
### Fixed
|
|
29
|
+
|
|
30
|
+
- The websocket chat listener, broken since Kick rotated its Pusher key.
|
|
31
|
+
- Token refresh inside a running event loop (0.x called `asyncio.run()` from async code).
|
|
32
|
+
- Token revocation now sends `token_type_hint` as RFC 7009 and Kick's API spec define it.
|
|
33
|
+
|
|
34
|
+
## 0.1.5 and earlier
|
|
35
|
+
|
|
36
|
+
See the git history.
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: kickpython
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Async Python client for the official Kick.com API: OAuth 2.1, chat, channels, moderation, rewards, webhooks and live chat.
|
|
5
|
+
Project-URL: Homepage, https://github.com/berkay-digital/kickpython
|
|
6
|
+
Project-URL: Source, https://github.com/berkay-digital/kickpython
|
|
7
|
+
Project-URL: Issues, https://github.com/berkay-digital/kickpython/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/berkay-digital/kickpython/blob/main/CHANGELOG.md
|
|
9
|
+
Project-URL: Kick API docs, https://docs.kick.com
|
|
10
|
+
Author-email: "berkay.digital" <contact@berkay.digital>
|
|
11
|
+
License-Expression: MIT
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: api,asyncio,bot,chat,kick,kick.com,oauth,streaming,webhooks
|
|
14
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
15
|
+
Classifier: Framework :: AsyncIO
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
25
|
+
Classifier: Topic :: Communications :: Chat
|
|
26
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
27
|
+
Classifier: Typing :: Typed
|
|
28
|
+
Requires-Python: >=3.10
|
|
29
|
+
Requires-Dist: aiohttp>=3.10
|
|
30
|
+
Requires-Dist: cryptography>=42
|
|
31
|
+
Requires-Dist: pydantic>=2.7
|
|
32
|
+
Provides-Extra: cloudflare
|
|
33
|
+
Requires-Dist: curl-cffi>=0.7; extra == 'cloudflare'
|
|
34
|
+
Description-Content-Type: text/markdown
|
|
35
|
+
|
|
36
|
+
# kickpython
|
|
37
|
+
|
|
38
|
+
Async Python client for the [Kick.com public API](https://docs.kick.com).
|
|
39
|
+
|
|
40
|
+
- OAuth 2.1 with PKCE, app tokens and user tokens. Tokens refresh on their own and persist in memory, a JSON file, SQLite or your own store.
|
|
41
|
+
- Every endpoint in Kick's API: users, channels, chat, moderation, channel rewards, livestreams, categories, event subscriptions, KICKs, ads and drops.
|
|
42
|
+
- Typed responses (pydantic models), cursor pagination, automatic retries on rate limits.
|
|
43
|
+
- Webhook receiver with signature checks, replay protection and typed event payloads.
|
|
44
|
+
- A websocket chat reader for bots that can't expose a public webhook URL (unofficial, see below).
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install kickpython
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Python 3.10 or newer.
|
|
51
|
+
|
|
52
|
+
## Quick start
|
|
53
|
+
|
|
54
|
+
Create an app at [kick.com/settings/developer](https://kick.com/settings/developer) to get a client ID and secret.
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
import asyncio
|
|
58
|
+
from kickpython import KickClient
|
|
59
|
+
|
|
60
|
+
async def main():
|
|
61
|
+
async with KickClient("CLIENT_ID", "CLIENT_SECRET") as kick:
|
|
62
|
+
channel = await kick.channels.get_by_slug("berkaydigital")
|
|
63
|
+
print(channel.slug, channel.is_live, channel.stream_title)
|
|
64
|
+
|
|
65
|
+
page = await kick.livestreams.list(language_codes=["en"], limit=10)
|
|
66
|
+
for stream in page:
|
|
67
|
+
print(stream.slug, stream.viewer_count)
|
|
68
|
+
|
|
69
|
+
asyncio.run(main())
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Without a user, requests use an app access token. The client fetches it with your client credentials and renews it when it expires.
|
|
73
|
+
|
|
74
|
+
## Acting as a user
|
|
75
|
+
|
|
76
|
+
Sending chat, editing a channel, moderating and managing rewards need a user's permission. Send the user through the OAuth flow once, then save their tokens:
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
from kickpython import KickClient, Scope, SQLiteTokenStore
|
|
80
|
+
|
|
81
|
+
kick = KickClient("CLIENT_ID", "CLIENT_SECRET", token_store=SQLiteTokenStore("kick_tokens.db"))
|
|
82
|
+
|
|
83
|
+
# 1. Send the user to request.url. Keep state and code_verifier for step 2.
|
|
84
|
+
request = kick.authorization_url(
|
|
85
|
+
"http://localhost:9765/callback",
|
|
86
|
+
[Scope.USER_READ, Scope.CHAT_WRITE, Scope.CHANNEL_WRITE],
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
# 2. Kick redirects back with ?code=...&state=... Check the state, then:
|
|
90
|
+
token = await kick.exchange_code(code, code_verifier=request.code_verifier,
|
|
91
|
+
redirect_uri=request.redirect_uri)
|
|
92
|
+
|
|
93
|
+
# 3. From now on, act as that user. Expired tokens refresh themselves.
|
|
94
|
+
me = kick.as_user(token.user_id)
|
|
95
|
+
await me.chat.send("Hello chat!")
|
|
96
|
+
await me.channels.update(stream_title="Building a bot")
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
[`examples/authorize.py`](https://github.com/berkay-digital/kickpython/blob/main/examples/authorize.py) does steps 1 and 2 for you from the command line.
|
|
100
|
+
|
|
101
|
+
Kick only grants the scopes you enabled for the app in its settings, even if you request more. Check `token.scopes` after the exchange. When a call fails because of a missing scope, the error says so and lists the scopes the token has.
|
|
102
|
+
|
|
103
|
+
More in [docs/authentication.md](https://github.com/berkay-digital/kickpython/blob/main/docs/authentication.md).
|
|
104
|
+
|
|
105
|
+
## Chat
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
me = kick.as_user(user_id)
|
|
109
|
+
|
|
110
|
+
await me.chat.send("posted by your app's bot account")
|
|
111
|
+
await me.chat.send("posted as the user", sender="user")
|
|
112
|
+
await me.chat.reply(message_id, "a threaded reply")
|
|
113
|
+
await me.chat.delete(message_id) # moderation:chat_message:manage
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
With `sender="bot"` (the default) the message goes to the chat of the user whose token you use. It appears under your app's bot account.
|
|
117
|
+
|
|
118
|
+
## Moderation, rewards and more
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
await me.moderation.timeout(user_id, minutes=10, reason="spam")
|
|
122
|
+
await me.moderation.ban(user_id)
|
|
123
|
+
await me.moderation.unban(user_id)
|
|
124
|
+
|
|
125
|
+
reward = await me.rewards.create("Hydrate", cost=500, is_user_input_required=False)
|
|
126
|
+
pending = await me.rewards.redemptions(status="pending")
|
|
127
|
+
failed = await me.rewards.accept(r.id for group in pending for r in group.redemptions)
|
|
128
|
+
|
|
129
|
+
board = await me.kicks.leaderboard(top=10)
|
|
130
|
+
await me.ads.start_break(60)
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
The full list of methods is in [docs/api.md](https://github.com/berkay-digital/kickpython/blob/main/docs/api.md).
|
|
134
|
+
|
|
135
|
+
## Pagination
|
|
136
|
+
|
|
137
|
+
Paginated endpoints return a `Page`. Iterate it, ask for the next one, or walk all of them:
|
|
138
|
+
|
|
139
|
+
```python
|
|
140
|
+
page = await kick.categories.list(names=["just"])
|
|
141
|
+
print([c.name for c in page])
|
|
142
|
+
|
|
143
|
+
next_page = await page.next() # None on the last page
|
|
144
|
+
|
|
145
|
+
async for stream in (await kick.livestreams.list(limit=100)).iter_all(max_pages=5):
|
|
146
|
+
...
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Webhooks
|
|
150
|
+
|
|
151
|
+
Kick sends events (chat messages, follows, subs, gifts, bans, stream start and stop, reward redemptions) to the webhook URL in your app settings. `WebhookHandler` checks each request's RSA signature against Kick's public key, rejects old or replayed deliveries and parses the payload:
|
|
152
|
+
|
|
153
|
+
```python
|
|
154
|
+
from kickpython import EventType, KickClient, WebhookEvent, WebhookHandler
|
|
155
|
+
|
|
156
|
+
kick = KickClient("CLIENT_ID", "CLIENT_SECRET")
|
|
157
|
+
hook = WebhookHandler(client=kick)
|
|
158
|
+
|
|
159
|
+
@hook.on(EventType.CHAT_MESSAGE_SENT)
|
|
160
|
+
async def on_chat(event: WebhookEvent):
|
|
161
|
+
msg = event.payload # kickpython.ChatMessage
|
|
162
|
+
print(msg.sender.username, msg.content)
|
|
163
|
+
|
|
164
|
+
# Subscribe a channel (with that user's token, or an app token plus broadcaster_user_id)
|
|
165
|
+
await kick.as_user(user_id).events.subscribe([EventType.CHAT_MESSAGE_SENT])
|
|
166
|
+
|
|
167
|
+
# Serve it with aiohttp, or call `await hook.handle(headers, body)` from any framework
|
|
168
|
+
app = hook.aiohttp_app("/kick/webhook")
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
See [docs/webhooks.md](https://github.com/berkay-digital/kickpython/blob/main/docs/webhooks.md) and [`examples/webhook_bot.py`](https://github.com/berkay-digital/kickpython/blob/main/examples/webhook_bot.py).
|
|
172
|
+
|
|
173
|
+
## Live chat without webhooks (unofficial)
|
|
174
|
+
|
|
175
|
+
Webhooks need a public HTTPS endpoint. For local bots, `LiveChat` reads chat from the same websocket feed the kick.com website uses. It needs no credentials and no public URL. Answer through the official API:
|
|
176
|
+
|
|
177
|
+
```python
|
|
178
|
+
from kickpython import KickClient, LiveChat, LiveChatMessage, SQLiteTokenStore
|
|
179
|
+
|
|
180
|
+
kick = KickClient("CLIENT_ID", "CLIENT_SECRET", token_store=SQLiteTokenStore("kick_tokens.db"))
|
|
181
|
+
live = LiveChat()
|
|
182
|
+
|
|
183
|
+
@live.on_message
|
|
184
|
+
async def on_message(msg: LiveChatMessage):
|
|
185
|
+
if msg.content == "!ping":
|
|
186
|
+
await kick.as_user(msg.broadcaster_user_id).chat.reply(msg.id, "pong")
|
|
187
|
+
|
|
188
|
+
await live.join("berkaydigital")
|
|
189
|
+
await live.run() # reconnects on its own
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
This feed is not part of Kick's public API, and Kick has changed it before. kickpython looks up the current connection details from Kick at startup to cope with that, but it can still break. Use webhooks for anything that must not miss messages. Details in [docs/live-chat.md](https://github.com/berkay-digital/kickpython/blob/main/docs/live-chat.md).
|
|
193
|
+
|
|
194
|
+
## Errors
|
|
195
|
+
|
|
196
|
+
All errors subclass `kickpython.KickError`. API errors are `KickAPIError` with `status`, `message` and `data`, and there is a subclass per status: `BadRequestError`, `UnauthorizedError`, `ForbiddenError`, `NotFoundError`, `ConflictError`, `RateLimitError` (with `retry_after`) and `ServerError`. `MissingTokenError` means there is no usable token for the call, for example when the user never authorized your app or their refresh token expired.
|
|
197
|
+
|
|
198
|
+
```python
|
|
199
|
+
from kickpython import BadRequestError
|
|
200
|
+
|
|
201
|
+
try:
|
|
202
|
+
await me.ads.start_break(30)
|
|
203
|
+
except BadRequestError as exc:
|
|
204
|
+
print(exc.data) # e.g. "CHANNEL_IS_NOT_LIVE"
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
The client retries 429 responses (honoring `Retry-After`) and failed GET requests up to `max_retries` times.
|
|
208
|
+
|
|
209
|
+
## Logging
|
|
210
|
+
|
|
211
|
+
kickpython logs to the `kickpython` logger and never configures logging itself. Tokens never appear in logs or in `repr()`.
|
|
212
|
+
|
|
213
|
+
```python
|
|
214
|
+
import logging
|
|
215
|
+
logging.basicConfig(level=logging.INFO)
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## Upgrading from 0.x
|
|
219
|
+
|
|
220
|
+
1.0 is a rewrite with a new API. See [docs/migrating.md](https://github.com/berkay-digital/kickpython/blob/main/docs/migrating.md). Existing `kick_tokens.db` files work with `SQLiteTokenStore`.
|
|
221
|
+
|
|
222
|
+
## Development
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
uv sync
|
|
226
|
+
uv run pytest # offline tests against a fake Kick server
|
|
227
|
+
uv run ruff check . && uv run mypy
|
|
228
|
+
KICK_CLIENT_ID=... KICK_CLIENT_SECRET=... uv run pytest -m live # read-only checks against Kick
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
## License
|
|
232
|
+
|
|
233
|
+
MIT
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
# kickpython
|
|
2
|
+
|
|
3
|
+
Async Python client for the [Kick.com public API](https://docs.kick.com).
|
|
4
|
+
|
|
5
|
+
- OAuth 2.1 with PKCE, app tokens and user tokens. Tokens refresh on their own and persist in memory, a JSON file, SQLite or your own store.
|
|
6
|
+
- Every endpoint in Kick's API: users, channels, chat, moderation, channel rewards, livestreams, categories, event subscriptions, KICKs, ads and drops.
|
|
7
|
+
- Typed responses (pydantic models), cursor pagination, automatic retries on rate limits.
|
|
8
|
+
- Webhook receiver with signature checks, replay protection and typed event payloads.
|
|
9
|
+
- A websocket chat reader for bots that can't expose a public webhook URL (unofficial, see below).
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install kickpython
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Python 3.10 or newer.
|
|
16
|
+
|
|
17
|
+
## Quick start
|
|
18
|
+
|
|
19
|
+
Create an app at [kick.com/settings/developer](https://kick.com/settings/developer) to get a client ID and secret.
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
import asyncio
|
|
23
|
+
from kickpython import KickClient
|
|
24
|
+
|
|
25
|
+
async def main():
|
|
26
|
+
async with KickClient("CLIENT_ID", "CLIENT_SECRET") as kick:
|
|
27
|
+
channel = await kick.channels.get_by_slug("berkaydigital")
|
|
28
|
+
print(channel.slug, channel.is_live, channel.stream_title)
|
|
29
|
+
|
|
30
|
+
page = await kick.livestreams.list(language_codes=["en"], limit=10)
|
|
31
|
+
for stream in page:
|
|
32
|
+
print(stream.slug, stream.viewer_count)
|
|
33
|
+
|
|
34
|
+
asyncio.run(main())
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Without a user, requests use an app access token. The client fetches it with your client credentials and renews it when it expires.
|
|
38
|
+
|
|
39
|
+
## Acting as a user
|
|
40
|
+
|
|
41
|
+
Sending chat, editing a channel, moderating and managing rewards need a user's permission. Send the user through the OAuth flow once, then save their tokens:
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
from kickpython import KickClient, Scope, SQLiteTokenStore
|
|
45
|
+
|
|
46
|
+
kick = KickClient("CLIENT_ID", "CLIENT_SECRET", token_store=SQLiteTokenStore("kick_tokens.db"))
|
|
47
|
+
|
|
48
|
+
# 1. Send the user to request.url. Keep state and code_verifier for step 2.
|
|
49
|
+
request = kick.authorization_url(
|
|
50
|
+
"http://localhost:9765/callback",
|
|
51
|
+
[Scope.USER_READ, Scope.CHAT_WRITE, Scope.CHANNEL_WRITE],
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
# 2. Kick redirects back with ?code=...&state=... Check the state, then:
|
|
55
|
+
token = await kick.exchange_code(code, code_verifier=request.code_verifier,
|
|
56
|
+
redirect_uri=request.redirect_uri)
|
|
57
|
+
|
|
58
|
+
# 3. From now on, act as that user. Expired tokens refresh themselves.
|
|
59
|
+
me = kick.as_user(token.user_id)
|
|
60
|
+
await me.chat.send("Hello chat!")
|
|
61
|
+
await me.channels.update(stream_title="Building a bot")
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
[`examples/authorize.py`](https://github.com/berkay-digital/kickpython/blob/main/examples/authorize.py) does steps 1 and 2 for you from the command line.
|
|
65
|
+
|
|
66
|
+
Kick only grants the scopes you enabled for the app in its settings, even if you request more. Check `token.scopes` after the exchange. When a call fails because of a missing scope, the error says so and lists the scopes the token has.
|
|
67
|
+
|
|
68
|
+
More in [docs/authentication.md](https://github.com/berkay-digital/kickpython/blob/main/docs/authentication.md).
|
|
69
|
+
|
|
70
|
+
## Chat
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
me = kick.as_user(user_id)
|
|
74
|
+
|
|
75
|
+
await me.chat.send("posted by your app's bot account")
|
|
76
|
+
await me.chat.send("posted as the user", sender="user")
|
|
77
|
+
await me.chat.reply(message_id, "a threaded reply")
|
|
78
|
+
await me.chat.delete(message_id) # moderation:chat_message:manage
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
With `sender="bot"` (the default) the message goes to the chat of the user whose token you use. It appears under your app's bot account.
|
|
82
|
+
|
|
83
|
+
## Moderation, rewards and more
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
await me.moderation.timeout(user_id, minutes=10, reason="spam")
|
|
87
|
+
await me.moderation.ban(user_id)
|
|
88
|
+
await me.moderation.unban(user_id)
|
|
89
|
+
|
|
90
|
+
reward = await me.rewards.create("Hydrate", cost=500, is_user_input_required=False)
|
|
91
|
+
pending = await me.rewards.redemptions(status="pending")
|
|
92
|
+
failed = await me.rewards.accept(r.id for group in pending for r in group.redemptions)
|
|
93
|
+
|
|
94
|
+
board = await me.kicks.leaderboard(top=10)
|
|
95
|
+
await me.ads.start_break(60)
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
The full list of methods is in [docs/api.md](https://github.com/berkay-digital/kickpython/blob/main/docs/api.md).
|
|
99
|
+
|
|
100
|
+
## Pagination
|
|
101
|
+
|
|
102
|
+
Paginated endpoints return a `Page`. Iterate it, ask for the next one, or walk all of them:
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
page = await kick.categories.list(names=["just"])
|
|
106
|
+
print([c.name for c in page])
|
|
107
|
+
|
|
108
|
+
next_page = await page.next() # None on the last page
|
|
109
|
+
|
|
110
|
+
async for stream in (await kick.livestreams.list(limit=100)).iter_all(max_pages=5):
|
|
111
|
+
...
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Webhooks
|
|
115
|
+
|
|
116
|
+
Kick sends events (chat messages, follows, subs, gifts, bans, stream start and stop, reward redemptions) to the webhook URL in your app settings. `WebhookHandler` checks each request's RSA signature against Kick's public key, rejects old or replayed deliveries and parses the payload:
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
from kickpython import EventType, KickClient, WebhookEvent, WebhookHandler
|
|
120
|
+
|
|
121
|
+
kick = KickClient("CLIENT_ID", "CLIENT_SECRET")
|
|
122
|
+
hook = WebhookHandler(client=kick)
|
|
123
|
+
|
|
124
|
+
@hook.on(EventType.CHAT_MESSAGE_SENT)
|
|
125
|
+
async def on_chat(event: WebhookEvent):
|
|
126
|
+
msg = event.payload # kickpython.ChatMessage
|
|
127
|
+
print(msg.sender.username, msg.content)
|
|
128
|
+
|
|
129
|
+
# Subscribe a channel (with that user's token, or an app token plus broadcaster_user_id)
|
|
130
|
+
await kick.as_user(user_id).events.subscribe([EventType.CHAT_MESSAGE_SENT])
|
|
131
|
+
|
|
132
|
+
# Serve it with aiohttp, or call `await hook.handle(headers, body)` from any framework
|
|
133
|
+
app = hook.aiohttp_app("/kick/webhook")
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
See [docs/webhooks.md](https://github.com/berkay-digital/kickpython/blob/main/docs/webhooks.md) and [`examples/webhook_bot.py`](https://github.com/berkay-digital/kickpython/blob/main/examples/webhook_bot.py).
|
|
137
|
+
|
|
138
|
+
## Live chat without webhooks (unofficial)
|
|
139
|
+
|
|
140
|
+
Webhooks need a public HTTPS endpoint. For local bots, `LiveChat` reads chat from the same websocket feed the kick.com website uses. It needs no credentials and no public URL. Answer through the official API:
|
|
141
|
+
|
|
142
|
+
```python
|
|
143
|
+
from kickpython import KickClient, LiveChat, LiveChatMessage, SQLiteTokenStore
|
|
144
|
+
|
|
145
|
+
kick = KickClient("CLIENT_ID", "CLIENT_SECRET", token_store=SQLiteTokenStore("kick_tokens.db"))
|
|
146
|
+
live = LiveChat()
|
|
147
|
+
|
|
148
|
+
@live.on_message
|
|
149
|
+
async def on_message(msg: LiveChatMessage):
|
|
150
|
+
if msg.content == "!ping":
|
|
151
|
+
await kick.as_user(msg.broadcaster_user_id).chat.reply(msg.id, "pong")
|
|
152
|
+
|
|
153
|
+
await live.join("berkaydigital")
|
|
154
|
+
await live.run() # reconnects on its own
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
This feed is not part of Kick's public API, and Kick has changed it before. kickpython looks up the current connection details from Kick at startup to cope with that, but it can still break. Use webhooks for anything that must not miss messages. Details in [docs/live-chat.md](https://github.com/berkay-digital/kickpython/blob/main/docs/live-chat.md).
|
|
158
|
+
|
|
159
|
+
## Errors
|
|
160
|
+
|
|
161
|
+
All errors subclass `kickpython.KickError`. API errors are `KickAPIError` with `status`, `message` and `data`, and there is a subclass per status: `BadRequestError`, `UnauthorizedError`, `ForbiddenError`, `NotFoundError`, `ConflictError`, `RateLimitError` (with `retry_after`) and `ServerError`. `MissingTokenError` means there is no usable token for the call, for example when the user never authorized your app or their refresh token expired.
|
|
162
|
+
|
|
163
|
+
```python
|
|
164
|
+
from kickpython import BadRequestError
|
|
165
|
+
|
|
166
|
+
try:
|
|
167
|
+
await me.ads.start_break(30)
|
|
168
|
+
except BadRequestError as exc:
|
|
169
|
+
print(exc.data) # e.g. "CHANNEL_IS_NOT_LIVE"
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
The client retries 429 responses (honoring `Retry-After`) and failed GET requests up to `max_retries` times.
|
|
173
|
+
|
|
174
|
+
## Logging
|
|
175
|
+
|
|
176
|
+
kickpython logs to the `kickpython` logger and never configures logging itself. Tokens never appear in logs or in `repr()`.
|
|
177
|
+
|
|
178
|
+
```python
|
|
179
|
+
import logging
|
|
180
|
+
logging.basicConfig(level=logging.INFO)
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## Upgrading from 0.x
|
|
184
|
+
|
|
185
|
+
1.0 is a rewrite with a new API. See [docs/migrating.md](https://github.com/berkay-digital/kickpython/blob/main/docs/migrating.md). Existing `kick_tokens.db` files work with `SQLiteTokenStore`.
|
|
186
|
+
|
|
187
|
+
## Development
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
uv sync
|
|
191
|
+
uv run pytest # offline tests against a fake Kick server
|
|
192
|
+
uv run ruff check . && uv run mypy
|
|
193
|
+
KICK_CLIENT_ID=... KICK_CLIENT_SECRET=... uv run pytest -m live # read-only checks against Kick
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## License
|
|
197
|
+
|
|
198
|
+
MIT
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# API reference
|
|
2
|
+
|
|
3
|
+
Every method is a coroutine. "User" in the token column means the call needs `kick.as_user(user_id)` (or a fixed `access_token`). "Any" works with an app token too.
|
|
4
|
+
|
|
5
|
+
Methods that take a list of IDs or slugs split it into several requests when it is longer than Kick's per-request limit.
|
|
6
|
+
|
|
7
|
+
## Users
|
|
8
|
+
|
|
9
|
+
| Method | Endpoint | Token |
|
|
10
|
+
| --- | --- | --- |
|
|
11
|
+
| `users.get(ids=None)` returns `list[User]` | `GET /public/v1/users` | Any. Without IDs, the authorized user |
|
|
12
|
+
| `users.me()` returns `User` | `GET /public/v1/users` | User |
|
|
13
|
+
|
|
14
|
+
## Channels
|
|
15
|
+
|
|
16
|
+
| Method | Endpoint | Token |
|
|
17
|
+
| --- | --- | --- |
|
|
18
|
+
| `channels.get(user_ids=..., slugs=...)` returns `list[Channel]` | `GET /public/v1/channels` | Any |
|
|
19
|
+
| `channels.get_by_slug(slug)`, `channels.get_by_user_id(id)` return `Channel` or `None` | same | Any |
|
|
20
|
+
| `channels.me()` returns `Channel` | same | User |
|
|
21
|
+
| `channels.update(stream_title=, category_id=, custom_tags=)` | `PATCH /public/v1/channels` | User, `channel:write` |
|
|
22
|
+
|
|
23
|
+
`Channel.category` is `None` when no category is set. `Channel.stream.key` and `.url` are only filled with `streamkey:read`.
|
|
24
|
+
|
|
25
|
+
## Chat
|
|
26
|
+
|
|
27
|
+
| Method | Endpoint | Token |
|
|
28
|
+
| --- | --- | --- |
|
|
29
|
+
| `chat.send(content, sender="bot", broadcaster_user_id=None, reply_to=None)` returns `ChatMessageSent` | `POST /public/v1/chat` | User, `chat:write` |
|
|
30
|
+
| `chat.reply(message_id, content, **kwargs)` | same | User, `chat:write` |
|
|
31
|
+
| `chat.delete(message_id)` | `DELETE /public/v1/chat/{id}` | User, `moderation:chat_message:manage` |
|
|
32
|
+
|
|
33
|
+
`sender="bot"` posts as your app's bot into the token owner's chat and ignores `broadcaster_user_id`. `sender="user"` posts as the token owner into `broadcaster_user_id`'s chat, which defaults to their own. Messages are limited to 500 characters and 2048 UTF-8 bytes.
|
|
34
|
+
|
|
35
|
+
## Moderation
|
|
36
|
+
|
|
37
|
+
All need a user token with `moderation:ban`. `broadcaster_user_id` defaults to the bound user.
|
|
38
|
+
|
|
39
|
+
| Method | Endpoint |
|
|
40
|
+
| --- | --- |
|
|
41
|
+
| `moderation.ban(user_id, broadcaster_user_id=None, reason=None)` | `POST /public/v1/moderation/bans` |
|
|
42
|
+
| `moderation.timeout(user_id, minutes, broadcaster_user_id=None, reason=None)` | same, with `duration` (1 to 10080 minutes) |
|
|
43
|
+
| `moderation.unban(user_id, broadcaster_user_id=None)` | `DELETE /public/v1/moderation/bans` |
|
|
44
|
+
|
|
45
|
+
## Channel rewards
|
|
46
|
+
|
|
47
|
+
User token. Reading needs `channel:rewards:read`, everything else `channel:rewards:write`. Only the app that created a reward can change, delete or resolve it.
|
|
48
|
+
|
|
49
|
+
| Method | Endpoint |
|
|
50
|
+
| --- | --- |
|
|
51
|
+
| `rewards.list()` returns `list[Reward]` | `GET /public/v1/channels/rewards` |
|
|
52
|
+
| `rewards.create(title, cost, description=, background_color=, is_enabled=, is_user_input_required=, should_redemptions_skip_request_queue=)` | `POST /public/v1/channels/rewards` |
|
|
53
|
+
| `rewards.update(reward_id, ...)` | `PATCH /public/v1/channels/rewards/{id}` |
|
|
54
|
+
| `rewards.delete(reward_id)` | `DELETE /public/v1/channels/rewards/{id}` |
|
|
55
|
+
| `rewards.redemptions(reward_id=, status=, ids=, cursor=)` returns `Page[RewardRedemptions]` | `GET /public/v1/channels/rewards/redemptions` |
|
|
56
|
+
| `rewards.accept(ids)`, `rewards.reject(ids)` return the failed ones as `list[FailedRedemption]` | `POST .../redemptions/accept`, `.../reject` |
|
|
57
|
+
|
|
58
|
+
## Livestreams
|
|
59
|
+
|
|
60
|
+
| Method | Endpoint | Token |
|
|
61
|
+
| --- | --- | --- |
|
|
62
|
+
| `livestreams.list(category_ids=, language_codes=, limit=, cursor=)` returns `Page[Livestream]` | `GET /public/v2/livestreams` | Any |
|
|
63
|
+
| `livestreams.for_users(user_ids)` returns `list[Livestream]` | `GET /public/v1/users/livestreams` | Any |
|
|
64
|
+
| `livestreams.stats()` returns `LivestreamsStats` | `GET /public/v1/livestreams/stats` | Any |
|
|
65
|
+
|
|
66
|
+
## Categories
|
|
67
|
+
|
|
68
|
+
| Method | Endpoint | Token |
|
|
69
|
+
| --- | --- | --- |
|
|
70
|
+
| `categories.list(names=, tags=, ids=, limit=, cursor=)` returns `Page[Category]` | `GET /public/v2/categories` | Any |
|
|
71
|
+
| `categories.search(name)` | same | Any |
|
|
72
|
+
| `categories.get(category_id)` returns `Category` or `None` | same | Any |
|
|
73
|
+
|
|
74
|
+
Name and tag filters match on substrings: `names=["just"]` finds "Just Chatting" and "Just Dance".
|
|
75
|
+
|
|
76
|
+
## Event subscriptions
|
|
77
|
+
|
|
78
|
+
| Method | Endpoint | Token |
|
|
79
|
+
| --- | --- | --- |
|
|
80
|
+
| `events.list(broadcaster_user_id=None)` returns `list[EventSubscription]` | `GET /public/v1/events/subscriptions` | Any |
|
|
81
|
+
| `events.subscribe(events, broadcaster_user_id=None)` returns `list[SubscriptionResult]` | `POST /public/v1/events/subscriptions` | App token with `broadcaster_user_id`, or user token with `events:subscribe` |
|
|
82
|
+
| `events.unsubscribe(ids)` | `DELETE /public/v1/events/subscriptions` | Any |
|
|
83
|
+
| `events.unsubscribe_all(broadcaster_user_id=None)` returns the count | list, then delete | Any |
|
|
84
|
+
|
|
85
|
+
`events` takes `EventType` values, strings, or `(name, version)` tuples. Kick reports problems per event, so check `result.ok` and `result.error`.
|
|
86
|
+
|
|
87
|
+
## KICKs, ads, drops
|
|
88
|
+
|
|
89
|
+
| Method | Endpoint | Token |
|
|
90
|
+
| --- | --- | --- |
|
|
91
|
+
| `kicks.leaderboard(top=10)` returns `KicksLeaderboard` | `GET /public/v1/kicks/leaderboard` | User, `kicks:read` |
|
|
92
|
+
| `ads.start_break(duration_seconds, id=None)` returns `AdBreak` | `POST /public/v1/ads/ad-break` | User, `ads:write` |
|
|
93
|
+
| `ads.status()` returns `AdBreakStatus` | `GET /public/v1/ads/ad-break-status` | User, `ads:read` |
|
|
94
|
+
| `ads.enroll()` | `POST /public/v1/ads/enroll` | User, `ads:write` |
|
|
95
|
+
| `drops.claims(campaign_id=, user_id=, claim_id=, external_status=, limit=, cursor=)` returns `Page[DropsClaim]` | `GET /public/v1/drops/claims` | App token of an organization app |
|
|
96
|
+
| `drops.update_claims({claim_id: status})` | `PATCH /public/v1/drops/claims` | same |
|
|
97
|
+
|
|
98
|
+
Ad break errors carry Kick's reason in `exc.data`, for example `CHANNEL_IS_NOT_LIVE` or `MAX_AD_BREAKS_REACHED`.
|
|
99
|
+
|
|
100
|
+
## OAuth and keys
|
|
101
|
+
|
|
102
|
+
| Method | What it does |
|
|
103
|
+
| --- | --- |
|
|
104
|
+
| `authorization_url(redirect_uri, scopes, state=None)` | Builds the consent URL. Not a coroutine |
|
|
105
|
+
| `exchange_code(code, code_verifier=, redirect_uri=, store=True)` | Code for a user token |
|
|
106
|
+
| `refresh_user_token(user_id)`, `refresh_all_user_tokens()` | Refresh now |
|
|
107
|
+
| `get_user_token(user_id)`, `get_app_token()` | Current valid token |
|
|
108
|
+
| `add_user_token(token)` | Save a token obtained elsewhere |
|
|
109
|
+
| `introspect(access_token=None)` | `POST /oauth/token/introspect` |
|
|
110
|
+
| `revoke_token(token, hint=None)`, `revoke_user(user_id)` | `POST /oauth/revoke` |
|
|
111
|
+
| `public_key()` | Kick's webhook signing key (PEM) |
|
|
112
|
+
|
|
113
|
+
## Models
|
|
114
|
+
|
|
115
|
+
Responses are pydantic models. Unknown fields Kick adds later stay available in `model.model_extra`, and `model.model_dump()` gives a plain dict. Kick's empty strings and zero dates (`0001-01-01T00:00:00Z`) become `None`.
|
|
116
|
+
|
|
117
|
+
Deprecated Kick endpoints (`/public/v1/categories`, `/public/v1/livestreams`, `/public/v1/token/introspect`) are not wrapped. kickpython uses their replacements.
|