Requests

API requests

pytwitcherapi.TwitchSession class is the central class for interacting with twitch.tv:

1
2
3
import pytwitcherapi

ts = pytwitcherapi.TwitchSession()

To query all top games use:

5
topgames = ts.top_games()

Get streams and playlist for every game:

 7
 8
 9
10
11
for game in topgames:
    streams = ts.get_streams(game=game)
    for stream in streams:
        channel = stream.channel
        playlist = ts.get_playlist(channel)

As you can see games, channels, streams are wrapped into objects. See pytwitcherapi.Game, pytwitcherapi.Channel, pytwitcherapi.Stream, pytwitcherapi.User.

You can use your own Client-ID for twitch by setting the environment variable PYTWITCHER_CLIENT_ID.

Custom requests

You can also issue custom requests. The pytwitcherapi.TwitchSession is actually a subclass of requests.Session. So basically you can use pytwitcherapi.TwitchSession.request() to issue arbitrary requests. To make it easier to use the different twitch APIs there are a few helpers.

You can get easy access to three different twitch APIs:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
import pytwitcherapi

ts = pytwitcherapi.TwitchSession()

topgames = ts.top_games()

for game in topgames:
    streams = ts.get_streams(game=game)
    for stream in streams:
        channel = stream.channel
        playlist = ts.get_playlist(channel)