Minor models reference#

This page contains all the models that are considered less often used in daily usage of the library. This generally includes models that are returned by API requests.

Attributes
class twitchio.ActiveExtension(data)#

Represents an active extension for a specified user

id#

ID of the extension.

Type

str

version#

Version of the extension.

Type

str

active#

Activation state of the extension.

Type

bool

name#

Name of the extension.

Type

str

x#

(Video-component Extensions only) X-coordinate of the placement of the extension. Could be None.

Type

int

y#

(Video-component Extensions only) Y-coordinate of the placement of the extension. Could be None.

Type

int

Attributes
class twitchio.AutomodCheckMessage(id: str, text: str, user: twitchio.models.PartialUser | int)#

Represents the message to check with automod

id#

Developer-generated identifier for mapping messages to results.

Type

str

text#

Message text.

Type

str

user_id#

User ID of the sender.

Type

int

Attributes
class twitchio.AutomodCheckResponse(data: dict)#

Represents the response to a message check with automod

id#

The message ID passed in the body of the check

Type

str

permitted#

Indicates if this message meets AutoMod requirements.

Type

bool

class twitchio.BanEvent(http: HTTPHandler, data: dict, broadcaster: PartialUser | User | None)#

Represents a user being banned from a channel.

id#

The event ID.

Type

str

type#

Type of ban event. Either moderation.user.ban or moderation.user.unban.

Type

str

timestamp#

The time the action occurred at.

Type

datetime.datetime

version#

The version of the endpoint.

Type

float

broadcaster#

The user whose channel the ban/unban occurred on.

Type

PartialUser

user#

The user who was banned/unbanned.

Type

PartialUser

moderator#

The user who performed the action.

Type

PartialUser

expires_at#

When the ban expires.

Type

Optional[datetime.datetime]

reason#

The reason the moderator banned/unbanned the user.

Type

str

Attributes
Methods
class twitchio.BaseToken(access_token: str)#

A base token container. This base class takes an access token, and does no validation on it before allowing it to be used for requests. This is useful for passing app access tokens.

x == y

Checks if the token is equal to another.

x != y

Checks if the token is not equal to another.

str(x)

Returns the token.

hash(x)

Returns the hash of the access token

New in version 3.0.

access_token#

The access token to use.

Type

str

coroutine get(http: HTTPHandler, handler: BaseTokenHandler, session: aiohttp.ClientSession) str#

This function is a coroutine. Ensures the token is still within the validation period, and then returns the current access token.

Parameters
  • http (HTTPHandler) – The HTTP session

  • handler (BaseTokenHandler) – The handler passed to your Client/Bot

  • session (ClientSession) – The session to use for validating the token

Raises

InvalidToken – This token is invalid

Returns

The access token

Return type

str

Attributes
class twitchio.BaseUser(id: int | str)#

A barebones representation of a user. This doesn’t have much use outside of being passed to methods that require a user object that simply contains an ID.

id#

The ID of the user.

Type

int

.. versionadded:: 3.0
Attributes
class twitchio.BitLeaderboardUser(http: HTTPHandler, data: dict)#

A representation of a user on the Bit Leaderboard. This contains all the methods of the PartialUser, but also contains the rank and score attributes.

id#

The id of the user.

Type

str

name#

The name of the user (this corresponds to the login field of the API).

Type

str | None

rank#

The users position on the leaderboard.

Type

int

score#

How many bits Bits the user has cheered.

Type

int

class twitchio.BitsLeaderboard(http: HTTPHandler, data: dict)#

Represents a Bits leaderboard from the twitch API.

started_at#

The time the leaderboard started.

Type

datetime.datetime

ended_at#

The time the leaderboard ended.

Type

:class`datetime.datetime`

leaders#

The current leaders of the Leaderboard.

Type

list[BitLeaderboardUser]

class twitchio.ChannelInfo(http: HTTPHandler, data: dict)#

Represents a channel’s current information

user#

The user whose channel information was requested.

Type

PartialUser

game_id#

Current game ID being played on the channel.

Type

int

game_name#

Name of the game being played on the channel.

Type

str

title#

Title of the stream.

Type

str

language#

Language of the channel.

Type

str

delay#

Stream delay in seconds.

Type

int

content_classification_labels#

The CCLs applied to the channel.

Type

list[str]

is_branded_content#

Boolean flag indicating if the channel has branded content.

Type

bool

class twitchio.ChannelTeams(http: HTTPHandler, data: dict)#

Represents the Twitch Teams of which the specified channel/broadcaster is a member

broadcaster#

User of the broadcaster.

Type

PartialUser

background_image_url#

URL for the Team background image.

Type

str

banner#

URL for the Team banner.

Type

str

created_at#

Date and time the Team was created.

Type

datetime.datetime

updated_at#

Date and time the Team was last updated.

Type

datetime.datetime

info#

Team description.

Type

str

thumbnail_url#

Image URL for the Team logo.

Type

str

team_name#

Team name.

Type

str

team_display_name#

Team display name.

Type

str

id#

Team ID.

Type

str

Attributes
class twitchio.ChatBadge(data: dict)#

Represents chat badges.

set_id#

An ID that identifies this set of chat badges. For example, Bits or Subscriber.

Type

str

versions#

The list of chat badges in this set.

Type

List[ChatBadgeVersion]

class twitchio.ChatBadgeVersion(data: dict)#

Represents the different versions of the chat badge.

id#

An ID that identifies this version of the badge. The ID can be any value.

Type

str

image_url_1x#

URL to the small version (18px x 18px) of the badge.

Type

str

image_url_2x#

URL to the medium version (36px x 36px) of the badge.

Type

str

image_url_4x#

URL to the large version (72px x 72px) of the badge.

Type

str

title#

The title of the badge.

Type

str

description#

The description of the badge.

Type

str

click_action#

The action to take when clicking on the badge. This can be None if no action is specified

Type

str | None

click_url#

The URL to navigate to when clicking on the badge. This can be None if no URL is specified.

Type

str | None

class twitchio.ChatSettings(http: HTTPHandler, data: dict)#

Represents current chat settings of a broadcaster / channel

broadcaster#

User of the broadcaster. Only returns the ID

Type

PartialUser

emote_mode#

Indicates whether emote only mode is enabled

Type

bool

follower_mode#

Indicates whether follower only chat is enabled

Type

bool

follower_mode_duration#

The length of time, in minutes, that the followers must have followed the broadcaster to participate in chat

Type

Optional[int]

slow_mode#

Indicates whether the chat is in slow mode

Type

bool

slow_mode_wait_time#

The amount of time, in seconds, that users need to wait between sending messages

Type

Optional[int]

subscriber_mode#

Indicates whether only users that subscribe to the broadcaster’s channel can talk in chat

Type

bool

unique_chat_mode#

Indicates whether the broadcaster requires users to post only unique messages in the chat room

Type

bool

moderator#

The User of the moderator, if provided. Only returns the ID

Type

Optional[PartialUser]

non_moderator_chat_delay#

Indicates whether the broadcaster adds a short delay before chat messages appear in the chat room

Type

Optional[bool]

non_moderator_chat_delay_duration#

The amount of time, in seconds, that messages are delayed from appearing in chat

Type

Optional[int]

Attributes
class twitchio.ChatterColor(http: HTTPHandler, data: dict)#

Represents chatters current name color.

user#

PartialUser of the chatter.

Type

PartialUser

color#

The color of the chatter’s name.

Type

str

class twitchio.CheerEmote(http: HTTPHandler, data: dict)#

Represents a Cheer Emote

prefix#

The string used to Cheer that precedes the Bits amount.

Type

str

tiers#

The tiers this Cheer Emote has

Type

CheerEmoteTier

type#

Shows whether the emote is global_first_party, global_third_party, channel_custom, display_only, or sponsored.

Type

str

order#

Order of the emotes as shown in the bits card, in ascending order.

Type

str

last_updated :class:`datetime.datetime`

The date this cheermote was last updated.

charitable#

Indicates whether this emote provides a charity contribution match during charity campaigns.

Type

bool

class twitchio.CheerEmoteTier(data: dict)#

Represents a Cheer Emote tier.

min_bits#

The minimum bits for the tier

Type

int

id#

The ID of the tier

Type

str

color#

The color of the tier

Type

str

images#

contains two dicts, light and dark. Each item will have an animated and static item, which will contain yet another dict, with sizes 1, 1.5, 2, 3, and 4. Ex. cheeremotetier.images["light"]["animated"]["1"]

Type

dict

can_cheer#

Indicates whether emote information is accessible to users.

Type

bool

show_in_bits_card#

Indicates whether twitch hides the emote from the bits card.

Type

:class`bool`

class twitchio.Clip(http: HTTPHandler, data: dict)#

Represents a Twitch Clip

id#

The ID of the clip.

Type

str

url#

The URL of the clip.

Type

str

embed_url#

The URL to embed the clip with.

Type

str

broadcaster#

The user whose channel the clip was created on.

Type

PartialUser

creator#

The user who created the clip.

Type

PartialUser

video_id#

The ID of the video the clip is sourced from.

Type

str

game_id#

The ID of the game that was being played when the clip was created.

Type

str

language#

The language, in an ISO 639-1 format, of the stream when the clip was created.

Type

str

title#

The title of the clip.

Type

str

views#

The amount of views this clip has.

Type

int

created_at#

When the clip was created.

Type

datetime.datetime

thumbnail_url#

The url of the clip thumbnail.

Type

str

Indicates if the clip is featured or not.

Type

bool

Attributes
class twitchio.ContentClassificationLabel(data: dict)#

Represents a Content Classification Label.

id#

Unique identifier for the CCL.

Type

str

description#

Localized description of the CCL.

Type

str

name#

Localized name of the CCL.

Type

str

class twitchio.CustomReward(http: HTTPHandler, obj: dict, user: PartialUser)#

Represents a Custom Reward object, as given by the api. Use get_custom_rewards() to fetch these

id#

The ID of the Custom Reward

Type

class:str

image#

The image of the Custom Reward. If none has been uploaded, this defaults to the default image provided

Type

str

background_color#

The background colour of the reward. This is a hex with a # prefix

Type

str

enabled#

Whether or not this reward is enabled

Type

:class:`bool

cost#

How much this reward costs to use

Type

int

title#

The title of this reward

Type

str

prompt#

The prompt the user sees when redeeming this reward

Type

str

input_required#

Whether this reward accepts input or not

Type

str

max_per_stream#

A tuple that indicates whether there is a maximum enabled (index 0) and what the maximum is, if enabled (index 1)

Type

Tuple[bool, int]

max_per_user_stream#

A tuple that indicates whether there is a per user maximum enabled (index 0) and what the maximum is, if enabled (index 1)

Type

Tuple[bool, int]

paused#

When True, users cannot redeem this reward

Type

:class`bool`

in_stock#

Is the reward currently in stock? If False, users cannot redeem this reward

Type

bool

redemptions_skip_queue#

Should redemptions be set to FULFILLED status immediately when redeemed and skip the request queue instead of the normal UNFULFILLED status

Type

:class:`bool

redemptions_current_stream#

How many times this reward has been redeemed in the current stream. Will be None if the stream is not live or max_per_stream is disabled

Type

Optional[int]

cooldown_until#

If not None, a timestamp that indicates when the cooldown for this reward ends

Type

Optional[datetime.datetime]

coroutine delete() None#

Deletes the custom reward

Return type

None

coroutine edit(title: str | None = None, prompt: str | None = None, cost: int | None = None, background_color: str | None = None, enabled: bool | None = None, input_required: bool | None = None, max_per_stream_enabled: bool | None = None, max_per_stream: int | None = None, max_per_user_per_stream_enabled: bool | None = None, max_per_user_per_stream: int | None = None, global_cooldown_enabled: bool | None = None, global_cooldown: int | None = None, paused: bool | None = None, redemptions_skip_queue: bool | None = None) Self#

Edits the reward. Note that apps can only modify rewards they have made.

Parameters
  • title (Optional[str]) – the new title of the reward

  • prompt (Optional[str]) – the new prompt for the reward

  • cost (Optional[int]) – the new cost for the reward

  • background_color (Optional[str]) – the new background color for the reward

  • enabled (Optional[bool]) – whether the reward is enabled or not

  • input_required (Optional[bool]) – whether user input is required or not

  • max_per_stream_enabled (Optional[bool]) – whether the stream limit should be enabled

  • max_per_stream (Optional[int]) – how many times this can be redeemed per stream

  • max_per_user_per_stream_enabled (Optional[bool]) – whether the user stream limit should be enabled

  • max_per_user_per_stream (Optional[int]) – how many times a user can redeem this reward per stream

  • global_cooldown_enabled (Optional[bool]) – whether the global cooldown should be enabled

  • global_cooldown (Optional[int]) – how many seconds the global cooldown should be

  • paused (Optional[bool]) – whether redemptions on this reward should be paused or not

  • redemptions_skip_queue (Optional[bool]) – whether redemptions skip the request queue or not

Return type

CustomReward itself.

coroutine get_redemptions(status: Literal['UNFULFILLED', 'FULFILLED', 'CANCELLED'], sort: Literal['OLDEST', 'NEWEST'] = 'OLDEST') HTTPAwaitableAsyncIterator[CustomRewardRedemption]#

Gets redemptions for this reward

Parameters
  • statusstr one of UNFULFILLED, FULFILLED or CANCELED

  • sort – Optional[str] the order redemptions are returned in. One of OLDEST, NEWEST. Default: OLDEST.

Methods
class twitchio.CustomRewardRedemption(http: HTTPHandler, obj: dict, parent: CustomReward | None)#

A redemption of a CustomReward

id#

The ID of the redemption

Type

str

user#

The user who redeemed the reward

Type

PartialUser

input#

The input from the user, if the reward requires it. Otherwise this is an empty string

Type

str

status#

The status of the redemption

Type

Literal[“UNFULFILLED”, “FULFILLED”, “CANCELLED”]

redeemed_at#

When the reward was redeemed

Type

datetime.datetime

reward#

The reward this was redeemed with. This will always be a CustomReward when fetched with CustomReward.get_redemptions()

Type

Union[PartialCustomReward, CustomReward]

coroutine fulfill() Self#

marks the redemption as fulfilled

Return type

itself.

coroutine refund() Self#

marks the redemption as cancelled

Return type

itself.

Attributes
class twitchio.Extension(data)#

Represents an extension for a specified user

id#

ID of the extension.

Type

str

version#

Version of the extension.

Type

str

active#

Activation state of the extension, for each extension type (component, overlay, mobile, panel).

Type

bool

class twitchio.ExtensionBuilder(panels: list[twitchio.models.Extension] | None = None, overlays: list[twitchio.models.Extension] | None = None, components: list[twitchio.models.Extension] | None = None)#

Represents an extension to be updated for a specific user

panels#

List of panels to update for an extension.

Type

list[Extension]

overlays#

List of overlays to update for an extension.

Type

list[Extension]

components#

List of components to update for an extension.

Type

list[Extension]

class twitchio.FollowEvent(http: HTTPHandler, data: dict, from_: User | PartialUser | None = None, to: User | PartialUser | None = None)#

Represents a Follow Event.

from_user#

The user that followed another user.

Type

Union[User, PartialUser]

to_user#

The user that was followed.

Type

Union[User, PartialUser]

followed_at#

When the follow happened.

Type

datetime.datetime

Attributes
Methods
class twitchio.Game(http: HTTPHandler, data: dict)#

Represents a Game on twitch

id#

Game ID.

Type

int

name#

Game name.

Type

str

box_art_url#

Template URL for the game’s box art.

Type

str

igdb_id#

The IGDB ID of the game. If this is not available to Twitch it will return None

Type

Optional[int]

art_url(width: int, height: int) str#

Adds width and height into the box art url

Parameters
  • width (int) – The width of the image

  • height (int) – The height of the image

Return type

str

class twitchio.Goal(http: HTTPHandler, data: dict)#

Represents a list of Goals for a broadcaster / channel

id#

An ID that uniquely identifies this goal

Type

str

broadcaster#

The broadcaster

Type

PartialUser

type#

The type of goal

Type

Literal[“follower”, “subscription”, “new_subscription”]

description#

A description of the goal, if specified

Type

str

current_amount#

The current value

Type

int

target_amount#

Number of Bits required to vote once with Bits

Type

int

created_at#

Date and time of when the broadcaster created the goal

Type

datetime.datetime

Attributes
class twitchio.HypeTrainContribution(http: HTTPHandler, data: dict)#

A Contribution to a Hype Train

total#

Total aggregated amount of all contributions by the top contributor. If type is BITS, total represents aggregate amount of bits used. If type is SUBS, aggregate total where 500, 1000, or 2500 represent tier 1, 2, or 3 subscriptions respectively. For example, if top contributor has gifted a tier 1, 2, and 3 subscription, total would be 4000.

Type

int

type#

Identifies the contribution method, either BITS or SUBS.

Type

str

user#

The user making the contribution.

Type

PartialUser

class twitchio.HypeTrainEvent(http: HTTPHandler, data: dict)#

Represents a Hype Train Event (progression)

id#

The ID of the event.

Type

str

event_id#

The ID of the Hype Train.

Type

str

type#

The type of the event. Currently only hypetrain.progression.

Type

str

version#

The version of the endpoint.

Type

str

broadcaster#

The user whose channel the Hype Train is occurring on.

Type

PartialUser

timestamp#

The time the event happened at.

Type

datetime.datetime

cooldown_end_time#

The time that another Hype Train can happen at.

Type

datetime.datetime

expiry#

The time that this Hype Train expires at.

Type

datetime.datetime

started_at#

The time that this Hype Train started at.

Type

datetime.datetime

last_contribution#

The last contribution to this Hype Train.

Type

HypeTrainContribution

level#

The level reached on this Hype Train (1-5).

Type

int

top_contributions#

The top contributors to the Hype Train.

Type

list[HypeTrainContribution]

contributions_total#

The total score towards completing the goal.

Type

int

goal#

The goal for the next Hype Train level

Type

int

class twitchio.IRCTokenHandler(access_token: str)#

A token handler to be used for IRC-only connections. You will not be able to make API calls while using this token handler. This handler does not accept a Client ID, or refresh token. If you want functionality such as refreshing your token, use the SimpleTokenHandler, or subclass BaseTokenHandler

user_token#

The token to use for all requests

Type

Token

coroutine event_token_expired(token: Token) twitchio.tokens.Token | None#

This function is a coroutine. Method to be overriden in a subclass.

This function is a special event hook into the HTTP system. It is called when a token expires and cannot be refreshed automatically. From here, you may return a new token for the HTTP system to use instead. Alternatively, you may return None to signal the HTTP system to call get_user_token() instead.

Note

This typically means that user interaction is required to acquire a new token. An exception to this is if you have not provided a client_secret in get_client_credentials(), then the library will not attempt to refresh tokens.

Parameters

token (Token) – The token that expired and could not be refreshed.

Return type

Token | None

coroutine event_token_refreshed(old: Token, new: Token) None#

This function could be a coroutine. Method to be overriden in a subclass.

This function is called whenever the library refreshes a user token. You do not need to do anything from this event, however this can be used to perform actions with the token. For example, this can be used to update tokens in a database, or inform a user.

When this is called, the token has already been refeshed

Parameters
  • old (Token) – The token before it was refreshed.

  • new (Token) – The token after it was refreshed.

coroutine get_client_credentials() tuple[str, str | None]#

This function could be a coroutine. Method to be overriden in a subclass.

This should return a tuple of (client id, client secret). The client secret is not required, however the client id is required to make requests to the twitch API. The client secret is required to automatically refresh user tokens when they expire, however it is not required to access the twitch API.

coroutine get_client_token() BaseToken#

This function could be a coroutine. Method to be overriden in a subclass.

This should return a client token (generated with client id and client secret). If not implemented, the library will attempt to generate one with the credentials returned from get_client_credentials().

Warning

If the library is unable to fetch any client token, it will hard crash. If you do not have means to generate a client token, you may not be able to use certain methods. You will also need to ensure any Client methods have a target parameter specified, as client tokens are used when no target user is specified.

Returns

The client token.

Return type

BaseToken

coroutine get_irc_token(shard_id: int) Token#

This function could be a coroutine. Method to be overriden in a subclass.

This should return a Token containing an OAuth token with the chat:login scope.

Parameters

user_name (str | None) – The name of the user to return a chat token for. Typically, this will be None when using the default shard manager. For a more in-depth explanation, see the shard manager documentation.

Returns

The token with which to connect

Return type

Token

coroutine get_user_token(user: BaseUser | PartialUser, scopes: tuple[str]) Token#

This function could be a coroutine. Method to be overriden in a subclass.

This function receives a user and a list of scopes that the request needs any one of to make the request. It should return a Token object.

Note

It is a good idea to pass a refresh token if you have one available, the library will automatically handle refreshing tokens if one is provided.

Parameters
  • user (BaseUser | BaseUser) – The user that a token is expected for.

  • scopes (tuple[str]) – A list of scopes that the endpoint needs one of. Any one or more of the scopes must be present on the returned token to successfully make the request

Returns

The token for the associated user.

Return type

Token

class twitchio.Marker(data: dict)#

Represents a stream Marker

id#

The ID of the marker.

Type

str

created_at#

When the marker was created.

Type

datetime.datetime

description#

The description of the marker.

Type

str

position#

The position of the marker, in seconds.

Type

int

url#

The url that leads to the marker.

Type

Optional[str]

class twitchio.MaybeActiveExtension(data)#

Represents an extension for a specified user that could be may be activated

id#

ID of the extension.

Type

str

version#

Version of the extension.

Type

str

name#

Name of the extension.

Type

str

can_activate#

Indicates whether the extension is configured such that it can be activated.

Type

bool

types#

Types for which the extension can be activated.

Type

list[str]

class twitchio.ModEvent(http: HTTPHandler, data: dict, broadcaster: PartialUser | User)#

Represents a mod add/remove action

id#

The ID of the event.

Type

str

type#

The type of the event.

Type

ModEventEnum

timestamp#

The timestamp of the event.

Type

datetime.datetime

version#

The version of the endpoint.

Type

str

broadcaster#

The user whose channel the event happened on.

Type

Union[PartialUser, User]

user#

The user being removed or added as a moderator.

Type

PartialUser

class twitchio.Poll(http: HTTPHandler, data: dict)#

Represents a list of Polls for a broadcaster / channel

id#

ID of a poll.

Type

str

broadcaster#

User of the broadcaster.

Type

PartialUser

title#

Question displayed for the poll.

Type

str

choices#

The poll choices.

Type

list[PollChoice]

bits_voting_enabled#

Indicates if Bits can be used for voting.

Type

bool

bits_per_vote#

Number of Bits required to vote once with Bits.

Type

int

channel_points_voting_enabled#

Indicates if Channel Points can be used for voting.

Type

bool

channel_points_per_vote#

Number of Channel Points required to vote once with Channel Points.

Type

int

status#

Poll status. Valid values: ACTIVE, COMPLETED, TERMINATED, ARCHIVED, MODERATED, INVALID

Type

str

duration#

Total duration for the poll (in seconds).

Type

int

started_at#

Date and time the the poll was started.

Type

datetime.datetime

ended_at#

Date and time the the poll was ended.

Type

datetime.datetime

class twitchio.PollChoice(data: dict)#

Represents a polls choices

id#

ID for the choice

Type

str

title#

Text displayed for the choice

Type

str

votes#

Total number of votes received for the choice across all methods of voting

Type

int

channel_points_votes#

Number of votes received via Channel Points

Type

int

bits_votes#

Number of votes received via Bits

Type

int

class twitchio.Prediction(http: HTTPHandler, data: dict)#

Represents channel point predictions

user#

The user who is streaming.

Type

PartialUser

prediction_id#

ID of the Prediction.

Type

str

title#

Title for the Prediction.

Type

str

winning_outcome_id#

ID of the winning outcome.

Type

str | None

outcomes#

List of possible outcomes for the Prediction.

Type

list[PredictionOutcome]

prediction_window#

Total duration for the Prediction (in seconds).

Type

int

prediction_status#

Status of the Prediction. One of ACTIVE, CANCELED, LOCKED, or RESOLVED.

Type

str

created_at#

Time for when the Prediction was created.

Type

datetime.datetime

ended_at#

Time for when the Prediction ended.

Type

datetime.datetime | None

locked_at#

Time for when the Prediction was locked.

Type

datetime.datetime | None

class twitchio.PredictionOutcome(http: HTTPHandler, data: dict)#

Represents a prediction outcome

outcome_id#

ID for the outcome.

Type

str

title#

Text displayed for outcome.

Type

str

channel_points#

Number of Channel Points used for the outcome.

Type

int

color#

Color for the outcome.

Type

str

users#

Number of unique uesrs that chose the outcome.

Type

int

top_predictors#

List of the top predictors. Could be None.

Type

list[Predictor]

property colour: str#

The colour of the prediction. Alias to color.

class twitchio.Predictor(http: HTTPHandler, data: dict)#

Represents a predictor

user#

The user who is streaming.

Type

PartialUser

channel_points_used#

Number of Channel Points used by the user.

Type

int

channel_points_won#

Number of Channel Points won by the user.

Type

int

Attributes
class twitchio.Raid(data: dict)#

Represents a raid for a broadcaster / channel

created_at#

Date and time of when the raid started.

Type

datetime.datetime

is_mature#

Indicates whether the stream being raided is marked as mature.

Type

bool

Attributes
class twitchio.Schedule(http: HTTPHandler, data: dict)#

Represents a channel’s stream schedule.

segments#

List of segments of a channel’s stream schedule.

Type

list[ScheduleSegment]

user#

The user of the channel associated to the schedule.

Type

PartialUser

vacation#

Vacation details of stream schedule.

Type

ScheduleVacation | Null

Attributes
class twitchio.ScheduleCategory(data: dict)#

Game or category details of a stream’s schedule

id#

The game or category ID.

Type

str

name#

The game or category name.

Type

str

class twitchio.ScheduleSegment(data: dict)#

Represents a list segments of a channel’s stream schedule

id#

The ID for the scheduled broadcast.

Type

str

start_time#

Scheduled start time for the scheduled broadcast

Type

datetime.datetime

end_time#

Scheduled end time for the scheduled broadcast

Type

datetime.datetime

title#

Title for the scheduled broadcast.

Type

str

canceled_until#

Used with recurring scheduled broadcasts. Specifies the date of the next recurring broadcast.

Type

datetime.datetime

category#

The game or category details for the scheduled broadcast.

Type

ScheduleCategory

is_recurring#

Indicates if the scheduled broadcast is recurring weekly.

Type

bool

Attributes
class twitchio.ScheduleVacation(data: dict)#

A schedule’s vacation details

start_time#

Start date of stream schedule vaction.

Type

datetime.datetime

end_time#

End date of stream schedule vaction.

Type

datetime.datetime

class twitchio.SearchUser(http: HTTPHandler, data: dict)#
class twitchio.SimpleTokenHandler(access_token: str, client_id: str, refresh_token: str | None = None, client_token: str | None = None, client_secret: str | None = None)#

A simple token handler, it takes an access token (and optionally a refresh token), and uses that access token for every request. You may also pass a client_token, which will be used for all requests that do not use a user token. If not provided, the user access token will be used for all requests.

user_token#

The token to use for all requests

Type

Token

client_token#

The token to use for all client credential requests (requests that don’t require user authorization)

Type

Optional[str]

client_id#

The client id associated with all tokens

Type

str

client_secret#

The client secret associated with the client id. This can be used to refresh tokens if they expire

Type

Optional[str]

coroutine event_token_expired(token: Token) twitchio.tokens.Token | None#

This function is a coroutine. Method to be overriden in a subclass.

This function is a special event hook into the HTTP system. It is called when a token expires and cannot be refreshed automatically. From here, you may return a new token for the HTTP system to use instead. Alternatively, you may return None to signal the HTTP system to call get_user_token() instead.

Note

This typically means that user interaction is required to acquire a new token. An exception to this is if you have not provided a client_secret in get_client_credentials(), then the library will not attempt to refresh tokens.

Parameters

token (Token) – The token that expired and could not be refreshed.

Return type

Token | None

coroutine event_token_refreshed(old: Token, new: Token) None#

This function could be a coroutine. Method to be overriden in a subclass.

This function is called whenever the library refreshes a user token. You do not need to do anything from this event, however this can be used to perform actions with the token. For example, this can be used to update tokens in a database, or inform a user.

When this is called, the token has already been refeshed

Parameters
  • old (Token) – The token before it was refreshed.

  • new (Token) – The token after it was refreshed.

coroutine get_client_credentials() tuple[str, str | None]#

This function could be a coroutine. Method to be overriden in a subclass.

This should return a tuple of (client id, client secret). The client secret is not required, however the client id is required to make requests to the twitch API. The client secret is required to automatically refresh user tokens when they expire, however it is not required to access the twitch API.

coroutine get_client_token() BaseToken#

This function could be a coroutine. Method to be overriden in a subclass.

This should return a client token (generated with client id and client secret). If not implemented, the library will attempt to generate one with the credentials returned from get_client_credentials().

Warning

If the library is unable to fetch any client token, it will hard crash. If you do not have means to generate a client token, you may not be able to use certain methods. You will also need to ensure any Client methods have a target parameter specified, as client tokens are used when no target user is specified.

Returns

The client token.

Return type

BaseToken

coroutine get_irc_token(shard_id: int) Token#

This function could be a coroutine. Method to be overriden in a subclass.

This should return a Token containing an OAuth token with the chat:login scope.

Parameters

user_name (str | None) – The name of the user to return a chat token for. Typically, this will be None when using the default shard manager. For a more in-depth explanation, see the shard manager documentation.

Returns

The token with which to connect

Return type

Token

coroutine get_user_token(user: BaseUser | PartialUser, scopes: tuple[str]) Token#

This function could be a coroutine. Method to be overriden in a subclass.

This function receives a user and a list of scopes that the request needs any one of to make the request. It should return a Token object.

Note

It is a good idea to pass a refresh token if you have one available, the library will automatically handle refreshing tokens if one is provided.

Parameters
  • user (BaseUser | BaseUser) – The user that a token is expected for.

  • scopes (tuple[str]) – A list of scopes that the endpoint needs one of. Any one or more of the scopes must be present on the returned token to successfully make the request

Returns

The token for the associated user.

Return type

Token

class twitchio.Stream(http: HTTPHandler, data: dict)#

Represents a Stream

id#

The current stream ID.

Type

int

user#

The user who is streaming.

Type

PartialUser

game_id#

Current game ID being played on the channel.

Type

int

game_name#

Name of the game being played on the channel.

Type

str

type#

Whether the stream is “live” or not.

Type

str

title#

Title of the stream.

Type

str

viewer_count#

Current viewer count of the stream

Type

int

started_at#

UTC timestamp of when the stream started.

Type

datetime.datetime

language#

Language of the channel.

Type

str

thumbnail_url#

Thumbnail URL of the stream.

Type

str

tag_ids#

Tag IDs that apply to the stream.

Type

list[str]

is_mature#

Indicates whether the stream is intended for mature audience.

Type

bool

class twitchio.SubscriptionEvent(http: HTTPHandler, data: dict, broadcaster: User | PartialUser | None = None)#

Represents a Subscription Event. This is for when someone subscribes to the target user.

broadcaster#

The user that was subscribed to.

Type

Union[User, PartialUser]

user#

The user who subscribed.

Type

Union[User, PartialUser]

tier#

The tier at which the user subscribed. Could be 1, 2, or 3.

Type

int

plan_name#

Name of the description. (twitch docs aren’t helpful, if you know what this is specifically please PR :) ).

Type

str

gift#

Whether the subscription is a gift.

Type

bool

gifter#

The user that gifted the sub, if applicable.

Type

PartialUser | None

class twitchio.Tag(http: HTTPHandler, data: dict)#

Represents a stream tag

id#

An ID that identifies the tag.

Type

str

auto#

Indicates whether the tag is an automatic tag.

Type

bool

localization_names#

A dictionary that contains the localized names of the tag.

Type

dict[str, str]

localization_descriptions#

A dictionary that contains the localized descriptions of the tag.

Type

str

class twitchio.Team(http: HTTPHandler, data: dict)#

Represents information for a specific Twitch Team

users#

List of users in the specified Team.

Type

list[PartialUser]

background_image_url#

URL for the Team background image.

Type

str

banner#

URL for the Team banner.

Type

str

created_at#

Date and time the Team was created.

Type

datetime.datetime

updated_at#

Date and time the Team was last updated.

Type

datetime.datetime

info#

Team description.

Type

str

thumbnail_url#

Image URL for the Team logo.

Type

str

team_name#

Team name.

Type

str

team_display_name#

Team display name.

Type

str

id#

Team ID.

Type

str

Methods
class twitchio.Token(access_token: str, refresh_token: str | None = None)#

A container around user OAuth tokens. This class will automatically ensure tokens are valid before allowing the library to use them, and will refresh tokens if possible.

x == y

Checks if the token is equal to another.

x != y

Checks if the token is not equal to another.

str(x)

Returns the token.

hash(x)

Returns the hash of the access token.

New in version 3.0.

access_token#

The token itself. This should not be prefixed with oauth:!

Type

str

refresh_token#

The refresh token associated with the access token. This is not useful unless you have provided a Client Secret from TokenHandler.get_client_credentials.

Type

str | None

coroutine get(http: HTTPHandler, handler: BaseTokenHandler, session: aiohttp.ClientSession) str#

This function is a coroutine. Ensures the token is still within the validation period, and then returns the current access token.

Parameters
  • http (HTTPHandler) – The HTTP session

  • handler (BaseTokenHandler) – The handler passed to your Client/Bot

  • session (ClientSession) – The session to use for validating the token

Raises

InvalidToken – This token is invalid

Returns

The access token

Return type

str

has_scope(scope: str) bool | None#

A helper function which determines whether the given token has a given scope or not. If the token has not previously been validated, this function will return None

Parameters

scope (str) – The scope to check this token for

Returns

Whether this token has the scope or not

Return type

Optional[bool]

coroutine refresh(handler: BaseTokenHandler, session: ClientSession) str#

This function is a coroutine. Refreshes the access token, if a refresh token has been provided. If one hasn’t been provided, this will raise InvalidToken.

Parameters
  • handler (BaseTokenHandler) – The token handler being used to refresh this token. This should be the same handler that was passed to your Client/Bot

  • session (ClientSession) – The session to use to refresh the token

Return type

str

Raises

RefreshFailure – The token could not be refreshed.

coroutine validate(http: HTTPHandler, handler: BaseTokenHandler, session: aiohttp.ClientSession) None#

This function is a coroutine. Validates the token, caching information on how this token is to be used. Tokens must be validated every hour, as per the dev docs.

Parameters
  • http (:class:`~twitchio.http.HTTPManager) – The HTTP session

  • handler (BaseTokenHandler) – The handler that was passed to your Client/Bot

  • session (ClientSession) – The session to use for validating the token

Raises

InvalidToken – This token is invalid

class twitchio.User(http: HTTPHandler, data: dict)#
class twitchio.UserBan(http: HTTPHandler, data: dict)#

Represents a banned user or one in timeout. This contains all the methods of the PartialUser, but also contains information about the banned user.

id#

The ID of the banned user.

Type

int

name#

The name of the banned user.

Type

str

created_at#

The date and time the ban was created.

Type

datetime.datetime

expires_at#

The date and time the timeout will expire. Is None if it’s a ban.

Type

Optional[datetime.datetime]

reason#

The reason for the ban/timeout.

Type

str

moderator#

The moderator that banned the user.

Type

PartialUser

class twitchio.Video(http: HTTPHandler, data: dict, user: PartialUser | User | None = None)#

Represents video information

id#

The ID of the video.

Type

int

user#

User who owns the video.

Type

PartialUser

title#

Title of the video

Type

str

description#

Description of the video.

Type

str

created_at#

Date when the video was created.

Type

datetime.datetime

published_at#

Date when the video was published.

Type

datetime.datetime

url#

URL of the video.

Type

str

thumbnail_url#

Template URL for the thumbnail of the video.

Type

str

viewable#

Indicates whether the video is public or private.

Type

str

view_count#

Number of times the video has been viewed.

Type

int

language#

Language of the video.

Type

str

type#

The type of video.

Type

str

duration#

Length of the video.

Type

str

coroutine delete() None#

This function is a coroutine.

Deletes the video. For bulk deletion see Client.delete_videos()

Parameters

token (str) – The users oauth token with the channel:manage:videos

Attributes
class twitchio.VideoMarkers(data: dict)#

Represents markers contained in a video

id#

The video id.

Type

str

markers#

The markers contained in the video.

Type

list[Marker]

class twitchio.WebhookSubscription(data: dict)#

Represents a Webhook Subscription

callback#

Where the webhook will be directed when triggered.

Type

str

expires_at#

When the webhook expires.

Type

datetime.datetime

topic#

The topic of the subscription.

Type

str