Async Python wrapper for Twitch EventSub and Helix API
Project description
twitch.py
An async Python wrapper for Twitch that handles real-time events via WebSocket EventSub and integrates with the Helix API.
Key Features
- Async/await support throughout
- Complete Twitch Helix API integration
- WebSocket EventSub for real-time events
- Built-in authentication and token management
Installing
To install the library, you can just run the following command:
# Linux/macOS
python3 -m pip install -U twitch.py
# Windows
py -3 -m pip install -U twitch.py
For the development version:
git clone https://github.com/mrsnifo/twitch.py
cd twitch.py
python3 -m pip install -U .
Quick Example
from twitch import App
async def main():
async with App('CLIENT_ID', 'CLIENT_SECRET') as app:
emotes = await app.application.get_global_emotes()
print(f'Found {len(emotes)} global emotes')
import asyncio
asyncio.run(main())
Client App Example
from twitch.eventsub import ClientApp, Event, ChannelChatMessageEvent
client = ClientApp('CLIENT_ID', 'CLIENT_SECRET')
@client.event
async def on_chat_message_v1(message: Event[ChannelChatMessageEvent]):
print(message.event.message)
@client.event
async def on_ready():
user = await client.add_user('ACCESS_TOKEN')
await client.eventsub.channel_chat_message(broadcaster_user_id=user.id, user_id=user.id)
# Uses availability-based shard selection. For multi-sharding use MultiShardClientApp.
client.run('CONDUIT_ID', shard_ids=(0,))
Client User Example
from twitch.eventsub import ClientUser, Event, ChannelFollowEvent
client = ClientUser('CLIENT_ID', 'CLIENT_SECRET')
@client.event
async def on_ready():
print('Client is ready!')
await client.eventsub.channel_follow()
@client.event
async def on_channel_follow_v2(message: Event[ChannelFollowEvent]):
print(f'{message.event.user.name} just followed!')
client.run('ACCESS_TOKEN')
More usage examples available in the examples folder.
Links
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file twitch_py-4.0.3.tar.gz.
File metadata
- Download URL: twitch_py-4.0.3.tar.gz
- Upload date:
- Size: 130.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c50b8dc27832c38efef8d330425f43bc2d41db029ed4a0d32850355e3a27fa66
|
|
| MD5 |
e3483ca145a92caf8a394798b441d3c3
|
|
| BLAKE2b-256 |
ed2985b7b927df9133a9b3e2361659c15fcaeedb7b5c914819654eedfb6f01de
|
File details
Details for the file twitch_py-4.0.3-py3-none-any.whl.
File metadata
- Download URL: twitch_py-4.0.3-py3-none-any.whl
- Upload date:
- Size: 145.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.23
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5a220f6ab09512c27e20aa150684fef2d505a8d22284bdbb3f2d28a18c66a6d7
|
|
| MD5 |
648973b9821a02f9a520e757078e295c
|
|
| BLAKE2b-256 |
f45faca448ead53791f8f39bfb27db526aecfb8ce09e5d269bb39d30bda70ef2
|