Skip to main content

Python wrapper for Kick.com API

Project description

KickPython - Python API Wrapper

A Python wrapper for the Kick.com API that provides easy access to Kick.com's public API endpoints and WebSocket chat functionality.

Installation

pip install kickpython

Features

  • OAuth 2.1 authentication with PKCE support
  • Automatic token storage and refresh
  • Channel management
  • Chat message sending and receiving
  • WebSocket-based chat listener
  • Support for channel category management
  • Proxy support

Usage

Basic Initialization

from kickpython import KickAPI

# For OAuth 2.1 authentication (recommended)
api = KickAPI(
    client_id="your_client_id",
    client_secret="your_client_secret",
    redirect_uri="your_redirect_uri",
    db_path="kick_tokens.db"  # Optional, defaults to kick_tokens.db
)

# With proxy support
api = KickAPI(
    client_id="your_client_id",
    client_secret="your_client_secret",
    redirect_uri="your_redirect_uri",
    proxy="proxy.example.com:8080",
    proxy_auth="username:password"
)

OAuth Authentication

# Generate authorization URL with PKCE
auth_data = api.get_auth_url([
    "user:read",
    "channel:read",
    "channel:write",
    "chat:write",
    "events:subscribe"
])

# The auth URL for user authorization
auth_url = auth_data["auth_url"]
code_verifier = auth_data["code_verifier"]
state = auth_data["state"]

# After user authorization, exchange the code for tokens
token_data = await api.exchange_code(code, code_verifier)

# Tokens are automatically stored and managed
await api.start_token_refresh()  # Start automatic token refresh

Chat Functionality

Sending Messages

# Send a chat message
await api.post_chat(
    channel_id="123",
    content="Hello from the bot!"
)

Listening to Chat Messages

# Define a message handler
async def message_handler(message):
    username = message['sender_username']
    content = message['content']
    badges = message['badges']
    chat_id = message['chat_id']
    print(f"{username}: {content}")

# Add the message handler
api.add_message_handler(message_handler)

# Connect to a channel's chat
await api.connect_to_chatroom("channel_username")
# Or connect using chatroom ID
await api.connect_to_chatroom("123456")

Channel Management

# Get channel information
channels = await api.get_channels()

# Update channel information
await api.update_channel(
    channel_id="123",
    category_id="456",
    stream_title="New Stream Title"
)

Category Management

# Get list of categories
categories = await api.get_categories()

# Search for specific categories
results = await api.get_categories(query="games")

# Get specific category
category = await api.get_category(category_id="123")

Complete Examples

OAuth Web Server

See examples/oauth.py for a complete Flask-based OAuth implementation that includes:

  • OAuth authorization flow with PKCE
  • Token management interface
  • Token refresh and revocation
  • Example API usage

Chat Bot

See examples/listen_all_channels.py for a chat bot example that:

  • Connects to multiple channels
  • Handles chat messages
  • Responds to commands
  • Handles reconnection

Error Handling

The API methods throw exceptions for error conditions:

  • ValueError for invalid input parameters
  • Exception for API errors with error messages

Example:

try:
    await api.post_chat(channel_id="123", content="")
except ValueError as e:
    print("Invalid parameters:", e)
except Exception as e:
    print("API error:", e)

Available Scopes

  • user:read - Access user information
  • channel:read - Access channel information
  • channel:write - Update channel metadata
  • chat:write - Send chat messages
  • events:subscribe - Subscribe to channel events

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

kickpython-0.1.3.tar.gz (17.9 kB view details)

Uploaded Source

Built Distribution

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

kickpython-0.1.3-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

Details for the file kickpython-0.1.3.tar.gz.

File metadata

  • Download URL: kickpython-0.1.3.tar.gz
  • Upload date:
  • Size: 17.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.0

File hashes

Hashes for kickpython-0.1.3.tar.gz
Algorithm Hash digest
SHA256 1aa65cc810dc6a19fd9fed4b182b675176534fb066428b57a645a9f9f15ea31d
MD5 345823ca6407af4a480c30bf6d46be5d
BLAKE2b-256 54bf47e0d87be73775e33e866929bfaf349d4f2355d305286d4b13347b433707

See more details on using hashes here.

File details

Details for the file kickpython-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: kickpython-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 14.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.0

File hashes

Hashes for kickpython-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a9e3260b4c4762d64658431a131790b656bb8bf69dfa7ea09fa9a29c66d7ead1
MD5 917bfea87fc02d8d92bddda8c6b29330
BLAKE2b-256 41c67a700c522d02902d83ce7e1c7edced8bbe75415092a0d7acb3f997aafb74

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