Skip to main content

mytwitch

Overview

Security Warning

As this package allows you to easily generate a user access token with the specified permissions, it too has access to send your token off to a third party without your knowledge. You are advised to always check the source code for such operations of any application you use and make sure this isn't the case.

Where to look?

It would be best for you to search through the entire package to assure you aren't being mislead. However, this is time consuming, so if you're not inclined, here are links to the supposedly relevant files. You can also browse the files after installation to make sure the published content doesn't differ from that in the repository.

Installation

python -m pip install mytwitch

Application setup for authentication

Redirect URI

  1. Log in to Twitch Developers.
  2. Go to the Applications tab.
  3. Register your application with the URL as http://localhost: followed by the port you choose to use. By default, this package uses 6319. This would be http://localhost:6319.

Client ID

  1. Log in to Twitch Developers.
  2. Go to the Applications tab.
  3. Select Manage by the application you're using.
  4. The client ID should be found on this page.

NOTE: Client IDs are public and may be shared. You may use Mytwitch's client ID, but you're advised to set up your own application in case this were to ever get removed for any reason. Mytwitch's client ID can be imported from mytwitch.client_id.

Examples

IRC

from mytwitch.auth import UserToken
from mytwitch.irc import TwitchIRC


client_id = 'abcdefghijklmnopqrstuvwxyz0123456789'
scope = ['chat:read']  # Permissions to read chat

# Create a user access token for authentication
user_token = UserToken(client_id, scope)

channel = 'twitch'  # Which channel to connect to
irc = TwitchIRC(user_token, [channel])  # Create your IRC

# Read incoming messages
for message in irc.feed():
    print(message)

PubSub

from mytwitch.auth import UserToken
from mytwitch.pubsub import TwitchPubSub


client_id = 'abcdefghijklmnopqrstuvwxyz0123456789'
scope = ['channel:read:redemptions']  # Permissions to read reward redemptions

# Create a user access token for authentication
user_token = UserToken(client_id, scope)


# Define a PubSub with your own events
class MyPubSub(TwitchPubSub):  # Inherit from `TwitchPubSub`
    
    async def on_open(self, websocket):
        print('PubSub has been opened.')

    async def on_message(self, ws, message):
        print(f'Message received:\n{message}\n\n')

    async def on_close(self):
        print('PubSub has been closed.')

    async def on_error(self, ws, exception):
        print(f'An error has occurred:\n{exception}\n\n')


# Topic for reading reward redemption
topics = [f'channel-points-channel-v1.{user_token.user_id}']
pubsub = MyPubSub(user_token, topics)  # Create your PubSub

# Start the PubSub connection
pubsub.connect()

User access token

from mytwitch.auth import UserToken

client_id = 'abcdefghijklmnopqrstuvwxyz0123456789'
scope = ['chat:read']

user_token = UserToken(
    client_id,  # Application client ID
    scope,      # Permissions you want

    immed_auth = True  # You can set this to False if you don't want
    # to generate a token on creation, as it opens a window in the browser
)

# Convert into a string to get the current token or generate a new one if necessary
print(f'My requested token is `{user_token}`')

Terminal Commands

There are commands for authentication if you don't want to have to set up a file for such simple operations. These commands use Mytwitch's client ID, by default, but you can specify your own with -C.

Create new token

python -m mytwitch auth -NS 'chat:read' 'chat:edit'

Revoke token

python -m mytwitch auth -RT 'abcdefghijklmnopqrstuvwxyz0123456789'

Metadata

Release files for mytwitch 0.9.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mytwitch 0.9.0
File Size Uploaded
mytwitch-0.9.0.tar.gz 24.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mytwitch 0.9.0
File Interpreter ABI Platform
mytwitch-0.9.0-py3-none-any.whl Python 3 none any Details

Total release size: 49.3 kB

Release files / mytwitch-0.9.0.tar.gz

Download URL mytwitch-0.9.0.tar.gz
Size 24.2 kB
Tags Source
SHA-256 checksum
How to use checksums
52297f8e33873622cf37c2077749e340cb2ec050c411885fcb10843169d62414
BLAKE2b-256 checksum
How to use checksums
24c05f7d67d9c8fdceab1ac1ca469333f7814ca522c508c60859318ca3418457
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.12 CPython/3.10.1 Linux/5.10.93-1-MANJARO

Release files / mytwitch-0.9.0-py3-none-any.whl

Download URL mytwitch-0.9.0-py3-none-any.whl
Size 25.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b3fdb802e48765dcb07e52247d10dd0845d13932b5a4ad0a795ae5a6ea01f758
BLAKE2b-256 checksum
How to use checksums
527f4d523db5b36ad6b524b602f9e91f37c1f6356202b2614412752761f9aed7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.12 CPython/3.10.1 Linux/5.10.93-1-MANJARO

Release history Release notifications | RSS feed

0.11.5

1 release file

0.11.2

2 release files

0.11.1

2 release files

0.11.0

2 release files

0.10.2

2 release files

This release

0.9.0 This release

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.0

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