kickpython
Async Python client for the Kick.com public API.
- 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.
- Every endpoint in Kick's API: users, channels, chat, moderation, channel rewards, livestreams, categories, event subscriptions, KICKs, ads and drops.
- Typed responses (pydantic models), cursor pagination, automatic retries on rate limits.
- Webhook receiver with signature checks, replay protection and typed event payloads.
- A websocket chat reader for bots that can't expose a public webhook URL (unofficial, see below).
pip install kickpython
Python 3.10 or newer.
Quick start
Create an app at kick.com/settings/developer to get a client ID and secret.
import asyncio
from kickpython import KickClient
async def main():
async with KickClient("CLIENT_ID", "CLIENT_SECRET") as kick:
channel = await kick.channels.get_by_slug("berkaydigital")
print(channel.slug, channel.is_live, channel.stream_title)
page = await kick.livestreams.list(language_codes=["en"], limit=10)
for stream in page:
print(stream.slug, stream.viewer_count)
asyncio.run(main())
Without a user, requests use an app access token. The client fetches it with your client credentials and renews it when it expires.
Acting as a user
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:
from kickpython import KickClient, Scope, SQLiteTokenStore
kick = KickClient("CLIENT_ID", "CLIENT_SECRET", token_store=SQLiteTokenStore("kick_tokens.db"))
# 1. Send the user to request.url. Keep state and code_verifier for step 2.
request = kick.authorization_url(
"http://localhost:9765/callback",
[Scope.USER_READ, Scope.CHAT_WRITE, Scope.CHANNEL_WRITE],
)
# 2. Kick redirects back with ?code=...&state=... Check the state, then:
token = await kick.exchange_code(code, code_verifier=request.code_verifier,
redirect_uri=request.redirect_uri)
# 3. From now on, act as that user. Expired tokens refresh themselves.
me = kick.as_user(token.user_id)
await me.chat.send("Hello chat!")
await me.channels.update(stream_title="Building a bot")
examples/authorize.py does steps 1 and 2 for you from the command line.
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.
More in docs/authentication.md.
Chat
me = kick.as_user(user_id)
await me.chat.send("posted by your app's bot account")
await me.chat.send("posted as the user", sender="user")
await me.chat.reply(message_id, "a threaded reply")
await me.chat.delete(message_id) # moderation:chat_message:manage
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.
Moderation, rewards and more
await me.moderation.timeout(user_id, minutes=10, reason="spam")
await me.moderation.ban(user_id)
await me.moderation.unban(user_id)
reward = await me.rewards.create("Hydrate", cost=500, is_user_input_required=False)
pending = await me.rewards.redemptions(status="pending")
failed = await me.rewards.accept(r.id for group in pending for r in group.redemptions)
board = await me.kicks.leaderboard(top=10)
await me.ads.start_break(60)
The full list of methods is in docs/api.md.
Pagination
Paginated endpoints return a Page. Iterate it, ask for the next one, or walk all of them:
page = await kick.categories.list(names=["just"])
print([c.name for c in page])
next_page = await page.next() # None on the last page
async for stream in (await kick.livestreams.list(limit=100)).iter_all(max_pages=5):
...
Webhooks
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:
from kickpython import EventType, KickClient, WebhookEvent, WebhookHandler
kick = KickClient("CLIENT_ID", "CLIENT_SECRET")
hook = WebhookHandler(client=kick)
@hook.on(EventType.CHAT_MESSAGE_SENT)
async def on_chat(event: WebhookEvent):
msg = event.payload # kickpython.ChatMessage
print(msg.sender.username, msg.content)
# Subscribe a channel (with that user's token, or an app token plus broadcaster_user_id)
await kick.as_user(user_id).events.subscribe([EventType.CHAT_MESSAGE_SENT])
# Serve it with aiohttp, or call `await hook.handle(headers, body)` from any framework
app = hook.aiohttp_app("/kick/webhook")
See docs/webhooks.md and examples/webhook_bot.py.
Live chat without webhooks (unofficial)
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:
from kickpython import KickClient, LiveChat, LiveChatMessage, SQLiteTokenStore
kick = KickClient("CLIENT_ID", "CLIENT_SECRET", token_store=SQLiteTokenStore("kick_tokens.db"))
live = LiveChat()
@live.on_message
async def on_message(msg: LiveChatMessage):
if msg.content == "!ping":
await kick.as_user(msg.broadcaster_user_id).chat.reply(msg.id, "pong")
await live.join("berkaydigital")
await live.run() # reconnects on its own
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.
Errors
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.
from kickpython import BadRequestError
try:
await me.ads.start_break(30)
except BadRequestError as exc:
print(exc.data) # e.g. "CHANNEL_IS_NOT_LIVE"
The client retries 429 responses (honoring Retry-After) and failed GET requests up to max_retries times.
Logging
kickpython logs to the kickpython logger and never configures logging itself. Tokens never appear in logs or in repr().
import logging
logging.basicConfig(level=logging.INFO)
Upgrading from 0.x
1.0 is a rewrite with a new API. See docs/migrating.md. Existing kick_tokens.db files work with SQLiteTokenStore.
Development
uv sync
uv run pytest # offline tests against a fake Kick server
uv run ruff check . && uv run mypy
KICK_CLIENT_ID=... KICK_CLIENT_SECRET=... uv run pytest -m live # read-only checks against Kick
License
MIT
Metadata
Release files for kickpython 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| kickpython-1.0.0.tar.gz | 66.7 kB | Without provenance | Details for kickpython-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| kickpython-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for kickpython-1.0.0-py3-none-any.whl |
Total release size: 113.2 kB
Release files / kickpython-1.0.0.tar.gz
| Download URL | kickpython-1.0.0.tar.gz |
|---|---|
| Size | 66.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
669aca8fd07e67305a1905c47895416dfbc6d654ae1d23fd07f50553fecaed06
|
|
BLAKE2b-256 checksum How to use checksums |
3c271924502a4c40880087fd7075432f237425316511534955a3fdb34bc8a7a2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Linux Mint","version":"22.3","id":"zena","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / kickpython-1.0.0-py3-none-any.whl
| Download URL | kickpython-1.0.0-py3-none-any.whl |
|---|---|
| Size | 46.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f46565fa9190ea1e900f92d1cb95cd0a75aa82d794f77df94e90ea5426a8f32d
|
|
BLAKE2b-256 checksum How to use checksums |
a8f805098c915d44d7c7de549fb6828a6800e9560da2555be893ff5620ed45c1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Linux Mint","version":"22.3","id":"zena","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for kickpython 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.