Skip to main content

Async Python wrapper for Twitch EventSub and Helix API

Project description

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

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-4.0.4.tar.gz (133.7 kB view details)

Uploaded Source

Built Distribution

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

twitch_py-4.0.4-py3-none-any.whl (148.2 kB view details)

Uploaded Python 3

File details

Details for the file twitch_py-4.0.4.tar.gz.

File metadata

  • Download URL: twitch_py-4.0.4.tar.gz
  • Upload date:
  • Size: 133.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for twitch_py-4.0.4.tar.gz
Algorithm Hash digest
SHA256 84c702c6a9ff68f634274caad082e641800f5e0af120f3f7f34748da20280f73
MD5 fc28260dca1d1fe05f41c3cfc6c9bd9d
BLAKE2b-256 5f15589caca7b506e5997e8ec76c0cc7ed00f111e65e89ddc866c80826498f46

See more details on using hashes here.

File details

Details for the file twitch_py-4.0.4-py3-none-any.whl.

File metadata

  • Download URL: twitch_py-4.0.4-py3-none-any.whl
  • Upload date:
  • Size: 148.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for twitch_py-4.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 64de124559839ce8ae94cac557277b0d415f5619f4e981ee42c32adf0612c42b
MD5 b6fefe6c076f430f4def84be227adbd6
BLAKE2b-256 7df8b976dfdda92e3e4426849433b0c38580b56a67dfa4aab92a3fe652b8d432

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