A full implementation of the Kick API and EventSub in Python 3.9+.
Heavily inspired on pyTwitchAPI. My mission is to maintain parity with the twitchAPI library for an easier manipulation of both libraries in any project.
Note
The library was intended to be called kickAPI to have parity with twitchAPI, but the name is already taken. So the library was re-branded to kick_api.
Update:
PyPI didn't like kick_api, a friend of mine recommended me betterKickAPI, and I liked it. So, re-branded to betterKickAPI.
Tip
Also try kickpython that includes its own WebSocket implementation!
Install using pip:
pip install betterKickAPI
Install using uv:
uv add betterKickAPI
Setting up an instance of the Kick API and get your User ID.
frombetterKickAPI.kickimportKickfrombetterKickAPI.helperimportfirstimportasyncioasyncdefkick_example():
# Initialize the kick instance, this will by default also create an app authentication for youkick=awaitKick('APP_ID', 'APP_SECRET')
users=awaitkick.get_users(slug='your_kick_user')
# print the ID of your userprint(user[0].broadcaster_user_id)
# run this exampleasyncio.run(kick_example())The Kick API knows 2 different authentications. App and User Authentication. Which one you need (or if one at all) depends on what calls you want to use.
frombetterKickAPI.kickimportKickkick=awaitKick('APP_ID', 'APP_SECRET')To get a user auth token, the user has to explicitly click "Allow access" on the Kick website. The library includes an Authenticator. Just remember to add http://localhost:36571 in your redirect URIs in the dev settings tab.
frombetterKickAPI.kickimportKickfrombetterKickAPI.oauthimportUserAuthenticatorfrombetterKickAPI.typeimportOAuthScopekick=awaitKick('APP_ID', 'APP_SECRET')
target_scope= [OAuthScope.CHANNEL_READ]
auth=UserAuthenticator(kick, target_scope, force_verify=False)
# this will open your default browser and prompt you with the kick auth websitetoken, refresh_token=awaitauth.authenticate()
awaitkick.set_user_authentication(token, target_scope, refresh_token)You can reuse this token and use the refresh_token to renew it:
frombetterKickAPI.oauthimportrefresh_access_tokennew_token, new_refresh_token=awaitrefresh_access_token('refresh_token', 'APP_ID', 'APP_SECRET')Optionally you can set a callback for both user access token refresh and app access token refresh.
frombetterKickAPI.kickimportKickasyncdefapp_refresh(token: str):
print(f'my new ap token is:{token}')
asyncdefuser_refresh(token: str, refresh_token: str):
print(f'my new user token is: {token}')
kick=awaitKick('APP_ID', 'APP_SECRET')
kick.app_auth_refresh_callback=app_refreshkick.user_auth_refresh_callback=user_refreshEventSub lets you listen for events that happen on Kick.
The EventSub client runs in its own process, calling the given callback function whenever an event happens.
Important
At the moment, the Kick API offers Webhook as the only method to use EventSub. But there's already plans on adding WebSockets.
- Considering getting rid of socketify because of linux dependencies.
- Add documentation.
- Add EventSub WebSockets when available.
- pyTwitchAPI: A Python 3.7 compatible implementation of the Twitch API, EventSub and Chat.
- KickPython: Kick.com Python Public API Wrapper