Real-time Twitch Event Handling and Helix API Integration in Python
Project description
twitch.py
A Python wrapper for Twitch It handles real-time events via WebSocket EventSub and integrates with the Helix API, all designed for easy asynchronous use.
Installation
To install twitch.py, use the appropriate command for your operating system:
For Windows:
py -3 -m pip install --upgrade twitch.py
For macOS/Linux:
python3 -m pip install --upgrade twitch.py
Quick Start
Here’s a simple example to get you started with twitch.py:
from twitch import Client
from twitch.types import eventsub
client = Client(client_id='YOUR_CLIENT_ID')
@client.event
async def on_ready():
print('Client is ready!')
@client.event
async def on_follow(data: eventsub.channels.FollowEvent):
await client.channel.chat.send_message(f'{data["user_name"]} just followed the channel!')
client.run('YOUR_USER_ACCESS_TOKEN')
OAuth Authentication
Authenticate easily with Twitch using the Device Flow authentication method:
from twitch import Client
from twitch.types import eventsub
from twitch.ext.oauth import DeviceAuthFlow, Scopes
client = Client(client_id='YOUR_CLIENT_ID')
DeviceAuthFlow(
client=client,
scopes=[Scopes.CHANNEL_READ_SUBSCRIPTIONS]
)
@client.event
async def on_code(code: str):
print(f'Go to https://www.twitch.tv/activate and enter this code: {code}')
@client.event
async def on_auth(access_token: str, refresh_token: str):
print(f'Access Token: {access_token}')
@client.event
async def on_subscribe(data: eventsub.channels.SubscribeEvent):
await client.channel.chat.send_message(f'{data["user_name"]} just Subscribed!')
client.run()
Documentation and Support
For more detailed instructions, visit the twitch.py Documentation.
Need help or want to join the community? Join the Discord server.
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
twitch_py-3.2.4.tar.gz
(88.1 kB
view hashes)
Built Distribution
twitch.py-3.2.4-py3-none-any.whl
(124.0 kB
view hashes)
Close
Hashes for twitch.py-3.2.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b794bf08779f0b73f86f374c8abf1b50bc38fdb73dc9281c6cc95532fb9c8bd |
|
MD5 | 1d50bc04bad3478d0dc5075c810a46c0 |
|
BLAKE2b-256 | 8a6ea911e63ac00234cfa699f4108e90a0debb9fc18bc833975cc0a65e8bc8af |