Skip to main content

A Python 3.9+ implementation of the Kick API and Webhook. Highly inspired on twitchAPI

Project description

Python Kick API

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 his own WebSocket implementation!

Installation

Install using pip:

pip install betterKickAPI

Install using uv:

uv add betterKickAPI

Usage

Basic API calls

Setting up an instance of the Kick API and get your User ID.

from betterKickAPI.kick import Kick
from betterKickAPI.helper import first
import asyncio

async def kick_example():
        # Initialize the kick instance, this will by default also create an app authentication for you
        kick = await Kick('APP_ID', 'APP_SECRET')

        # this returns an async generator that can be used to iterate over all results
        # but we are just interested in the first result
        # using the first helper makes this easy
        user = await first(kick.get_users(slug='your_kick_user'))
        # print the ID of your user
        print(user.broadcaster_user_id)

# run this example
asyncio.run(kick_example())

Authentication

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.

App Authentication

from betterKickAPI.kick import Kick
kick = await Kick('APP_ID', 'APP_SECRET')

User Authentication

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.

from betterKickAPI.kick import Kick
from betterKickAPI.oauth import UserAuthenticator
from betterKickAPI.type import OAuthScope

kick = await Kick('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 website
token, refresh_token = await auth.authenticate()

await kick.set_user_authentication(token, target_scope, refresh_token)

You can reuse this token and use the refresh_token to renew it:

from betterKickAPI.oauth import refresh_access_token
new_token, new_refresh_token = await refresh_access_token('refresh_token', 'APP_ID', 'APP_SECRET')

AuthToken refresh callback

Optionally you can set a callback for both user access token refresh and app access token refresh.

from betterKickAPI.kick import Kick

async def app_refresh(token: str):
        print(f'my new ap token is:{token}')

async def user_refresh(token: str, refresh_token: str):
        print(f'my new user token is: {token}')

kick = await Kick('APP_ID', 'APP_SECRET')
kick.app_auth_refresh_callback = app_refresh
kick.user_auth_refresh_callback = user_refresh

EventSub

EventSub 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.

TODO

  • Considering getting rid of socketify because of linux dependencies.
  • Add documentation.
  • Add EventSub WebSockets when available.

Acknowledges

  • pyTwitchAPI: A Python 3.7 compatible implementation of the Twitch API, EventSub and Chat.
  • KickPython: Kick.com Python Public API Wrapper

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

betterkickapi-1.0.0.tar.gz (33.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

betterkickapi-1.0.0-py3-none-any.whl (39.8 kB view details)

Uploaded Python 3

File details

Details for the file betterkickapi-1.0.0.tar.gz.

File metadata

  • Download URL: betterkickapi-1.0.0.tar.gz
  • Upload date:
  • Size: 33.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.7

File hashes

Hashes for betterkickapi-1.0.0.tar.gz
Algorithm Hash digest
SHA256 d87597668da6829f8e59256d27fba35334d34fe6291a8efaf7f772c75c55fde4
MD5 bf2286084de982a1913e88abdba6ce6d
BLAKE2b-256 117d00d29be2d3707cf53f88c61488c6a5e49ec8f7fcb2f764869234daca3c02

See more details on using hashes here.

File details

Details for the file betterkickapi-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for betterkickapi-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c70eaf15c6f68b1ac3ad0749e0f0e216fd6d5094f1a05e3844ec9f6136946d66
MD5 03f53dae1c88f5e429092c89de6d2aba
BLAKE2b-256 89f418b671705462175309cff3483d3e2dae7dba9ccede5836f6d50d09b867c8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page