Skip to main content

twitch.py

PyPI - Version Python Versions

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

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)

Source distribution for twitch.py 4.0.4
File Size Uploaded
twitch_py-4.0.4.tar.gz 133.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for twitch.py 4.0.4
File Interpreter ABI Platform
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

Release history Release notifications | RSS feed

This release

4.0.4 This release

2 release files

4.0.3

2 release files

4.0.2

2 release files

4.0.1

2 release files

4.0.0

2 release files

3.2.10

2 release files

3.2.9

2 release files

3.2.8

2 release files

3.2.7

2 release files

3.2.6

2 release files

3.2.5

2 release files

3.2.4

2 release files

3.2.3

2 release files

3.2.2

2 release files

3.2.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page