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
Metadata
Release files for twitch.py 4.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| twitch_py-4.0.4.tar.gz | 133.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| twitch_py-4.0.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 281.9 kB
Release files / twitch_py-4.0.4.tar.gz
| Download URL | twitch_py-4.0.4.tar.gz |
|---|---|
| Size | 133.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
84c702c6a9ff68f634274caad082e641800f5e0af120f3f7f34748da20280f73
|
|
BLAKE2b-256 checksum How to use checksums |
5f15589caca7b506e5997e8ec76c0cc7ed00f111e65e89ddc866c80826498f46
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|
Release files / twitch_py-4.0.4-py3-none-any.whl
| Download URL | twitch_py-4.0.4-py3-none-any.whl |
|---|---|
| Size | 148.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
64de124559839ce8ae94cac557277b0d415f5619f4e981ee42c32adf0612c42b
|
|
BLAKE2b-256 checksum How to use checksums |
7df8b976dfdda92e3e4426849433b0c38580b56a67dfa4aab92a3fe652b8d432
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|
Security for twitch.py 4.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.