Skip to main content

Real-time Twitch Event Handling and Helix API Integration in Python

Project description

twitch.py

PyPI - Version Python Versions

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

Uploaded Source

Built Distribution

twitch_py-3.2.10-py3-none-any.whl (126.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: twitch_py-3.2.10.tar.gz
  • Upload date:
  • Size: 90.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for twitch_py-3.2.10.tar.gz
Algorithm Hash digest
SHA256 588cf5b2d218b864ae503a385cbd878fd672b78ca4f27640ec2e75107e61bc64
MD5 def87569e1cb29d75a8af878bf73516a
BLAKE2b-256 e4133d922e8ab3e77f60c53762385f13bf123e833dd06e9d421f43f7fd9e396e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: twitch_py-3.2.10-py3-none-any.whl
  • Upload date:
  • Size: 126.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for twitch_py-3.2.10-py3-none-any.whl
Algorithm Hash digest
SHA256 ef0c7fbd3d8e2283f31e58fd89e7316060b0a2dce8d194404caeefe2f95c8904
MD5 a76bc0409c8a65076ed85722c975124e
BLAKE2b-256 9bb55cc82ca6bda417d2720eee3c8eddceb32e32555173dc30a5f8b7da25c455

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page