Models¶
- async forfetch_shards
- asyncupdate_shard_count
- class twitchio.ConduitInfo¶
A special class wrapping
Conduitassigned only toAutoClientandAutoBot.This class serves as an abstraction layer to managing the
Conduitassigned toAutoClientorAutoBotand contains various information and helper methods.Warning
The should not need to create this class yourself. Instead you can access it via
conduit_info.- property conduit: twitchio.models.eventsub_.Conduit | None¶
A property returning the
Conduitthat theAutoClientcurrently has ownership of. Could beNoneif a conduit has not yet been assigned, however this is usually done automatically during the startup stages of theAutoClient.
- property shard_count: int | None¶
Property returning the amount of shards the
AutoClientcurrently contains as anint. Could beNoneif a conduit has not yet been assigned, however this is usually done automatically during the startup stages of theAutoClient.
- property id: str | None¶
Property returning the ID of the
Conduitthat theAutoClientcurrently has ownership of. Could beNoneif a conduit has not yet been assigned, however this is usually done automatically during the startup stages of theAutoClient.
- property websockets: mappingproxy[str, twitchio.eventsub.websockets.Websocket]¶
Property returning a mapping of Websocket Shard-ID to Websocket that are currently active and assigned to the underlying
Conduit.Warning
This property exists only for those requiring lower level access over the underlying websocket(s); however ideally the websocket(s) should not be altered or interfered with. The mapping and property itself cannot be altered.
- async update_shard_count(shard_count: int, /, *, assign_transports: bool = True) Self¶
This function is a coroutine.
Method wrapping
twitchio.Conduit.update()which updates the number of shards assigned to theConduit. This method can be used to scale theConduitup (more shards) or down with less shards.Warning
Caution should be used when scaling multi-process solutions that connect to the same Conduit. In this particular case it is more likely appropriate to close down and restart each instance and adjust the
shard_idsparameter onAutoClientaccordingly. However this method can be called withassign_transports=Falsefirst to allow each instance to easily adjust when restarted.- Parameters
shard_count (
int) – A positional-onlyintwhich is the new amount of shards theConduitshould contain. The amount of shards should be between1and20_000.assign_transports (
bool) – A keyword-onlyboolset which determines whether new websockets should be created and assigned to the Conduit. This should be set toFalsein multi-instance/process setups that require theAutoClient’s to be restarted to rebalance shards accordingly. Defaults toTruewhich is the best case for a single instance ofAutoClient.
- Raises
MissingConduit – No
Conduithas been assigned to theAutoClient.ValueError – The
shard_countparameter cannot be lower than1and no higher than20_000.HTTPException – A an error occurred making the request to Twitch.
- Returns
Returns the updated
ConduitInfoand allows for chaining methods and attributes.- Return type
- fetch_shards(*, status: ShardStatus | None = None) HTTPAsyncIterator[ConduitShard]¶
This function returns a
HTTPAsyncIteratorMethod wrapping
twitchio.Conduit.fetch_shards()which returns the shard info for the Conduit retrieved from the Twitch API.Note
The Shard ID’s contained in the objects returned from this method may differ to the shard ID’s associated with
websockets. If you need to compare, each websocket has an attribute namedsession_idwhich can be used instead.Status
Description
enabledThe shard is enabled.
webhook_callback_verification_pendingThe shard is pending verification of the specified callback URL.
webhook_callback_verification_failedThe specified callback URL failed verification.
notification_failures_exceededThe notification delivery failure rate was too high.
websocket_disconnectedThe client closed the connection.
websocket_failed_ping_pongThe client failed to respond to a ping message.
websocket_received_inbound_trafficThe client sent a non-pong message. Clients may only send pong messages (and only in response to a ping message).
websocket_internal_errorThe Twitch WebSocket server experienced an unexpected error.
websocket_network_timeoutThe Twitch WebSocket server timed out writing the message to the client.
websocket_network_errorThe Twitch WebSocket server experienced a network error writing the message to the client.
websocket_failed_to_reconnectThe client failed to reconnect to the Twitch WebSocket server within the required time after a Reconnect Message.
- Parameters
status (str) – An optional
strwhich when provided, filters the shards by their status on the API. Possible statuses are listed above. Defaults toNonewhich fetches all shards.- Returns
An
HTTPAsyncIteratorwhich can be awaited or used withasync forto retrieve theConduitShard’s.- Return type
HTTPAsyncIterator[
ConduitShard]- Raises
MissingConduit – No
Conduithas been assigned to theAutoClient.HTTPException – An error occurred making the request to Twitch.
- asyncdelete
- async forfetch_shards
- asyncupdate
- class twitchio.Conduit¶
The
Conduitmodel which is returned from various API endpoints relating to Conduits on Twitch.This class can be used to manage the underlying Conduit, however for a more intuitive approach see:
AutoClientorAutoBotwhich wraps this class and provides aConduitInfoclass instead.Supported Operations¶
Operation
Usage(s)
Description
__str__
str(conduit),f"{conduit}"Return the official str represntation.
__repr__
repr(conduit),f"{conduit!r}"Return the official represntation.
__eq__
conduit == other,conduit != otherCompare equality of two conduits.
- async delete() None¶
This function is a coroutine.
Method to delete the associated
Conduitfrom the API.- Returns
Successfully removed the
Conduit- Return type
None
- Raises
HTTPException –
404- Conduit was not found or you do not own this Conduit.
- async update(shard_count: int, /) Conduit¶
This function is a coroutine.
Method which updates the underlying Conduit on the Twitch API with the provided
shard_count.Important
If you are using
AutoClientorAutoBotthis will not update the underlying websocket connections. See:update_shard_count()instead.- Parameters
shard_count (int) – The new amount of shards the Conduit should be assigned. Should be between
1and20_000.- Raises
ValueError –
shard_countmust be between1and20_000.- Returns
The updated
Conduit.- Return type
- fetch_shards(*, status: ShardStatus | None = None) HTTPAsyncIterator[ConduitShard]¶
This function returns a
HTTPAsyncIteratorMethod which returns the shards for the Conduit retrieved from the Twitch API.
Status
Description
enabledThe shard is enabled.
webhook_callback_verification_pendingThe shard is pending verification of the specified callback URL.
webhook_callback_verification_failedThe specified callback URL failed verification.
notification_failures_exceededThe notification delivery failure rate was too high.
websocket_disconnectedThe client closed the connection.
websocket_failed_ping_pongThe client failed to respond to a ping message.
websocket_received_inbound_trafficThe client sent a non-pong message. Clients may only send pong messages (and only in response to a ping message).
websocket_internal_errorThe Twitch WebSocket server experienced an unexpected error.
websocket_network_timeoutThe Twitch WebSocket server timed out writing the message to the client.
websocket_network_errorThe Twitch WebSocket server experienced a network error writing the message to the client.
websocket_failed_to_reconnectThe client failed to reconnect to the Twitch WebSocket server within the required time after a Reconnect Message.
- Parameters
status (str) – An optional
strwhich when provided, filters the shards by their status on the API. Possible statuses are listed above. Defaults toNonewhich fetches all shards.- Returns
An
HTTPAsyncIteratorwhich can be awaited or used withasync forto retrieve theConduitShard’s.- Return type
HTTPAsyncIterator[
ConduitShard]- Raises
HTTPException – An error occurred making the request to Twitch.
- class twitchio.ConduitShard¶
ConduitShard model containing various information about a Shard on a
Conduit.- method¶
A str literal of either
websocketorwebhook, indicating what transport this shard uses.- Type
- session_id¶
If
method == websocket, this will be thesession_idof the websocket. Could beNoneif the shard is not connected ormethod == webhook.- Type
str | None
- connected_at¶
A
datetime.datetimeof when the shard was connected in UTC. Only availabe whenmethod == websocket.- Type
datetime.datetime| None
- disconnected_at¶
A
datetime.datetimeof when the shard was lost connection in UTC. Only availabe whenmethod == websocket.- Type
datetime.datetime| None
- callback¶
The URL that notifications for the shard are sent via Webhooks. Only availabe when
method == webhook.- Type
str | None
- property status: ShardStatus¶
Property returning the status of the shard.
The possible statuses are provided below.
Status
Description
enabledThe shard is enabled.
webhook_callback_verification_pendingThe shard is pending verification of the specified callback URL.
webhook_callback_verification_failedThe specified callback URL failed verification.
notification_failures_exceededThe notification delivery failure rate was too high.
websocket_disconnectedThe client closed the connection.
websocket_failed_ping_pongThe client failed to respond to a ping message.
websocket_received_inbound_trafficThe client sent a non-pong message. Clients may only send pong messages (and only in response to a ping message).
websocket_internal_errorThe Twitch WebSocket server experienced an unexpected error.
websocket_network_timeoutThe Twitch WebSocket server timed out writing the message to the client.
websocket_network_errorThe Twitch WebSocket server experienced a network error writing the message to the client.
websocket_failed_to_reconnectThe client failed to reconnect to the Twitch WebSocket server within the required time after a Reconnect Message.
- class twitchio.MultiSubscribePayload¶
Payload received from the
multi_subscribe()method.This payload contains a list of
MultiSubscribeSuccesswhich are the successful subscriptions and another list ofMultiSubscribeErrorwhich are any subscriptions that failed.This payload is only returned when the parameters
waitis set toTrueandstop_on_errorisFalseinmulti_subscribe().If the
waitparameter inmulti_subscribe()is set toFalse, you can await the returnedasyncio.Tasklater to retrieve this payload.- success¶
A list of
MultiSubscribeSuccesscontaining information about the successful subscriptions.- Type
list[
MultiSubscribeSuccess]
- errors¶
A list of
MultiSubscribeErrorcontaining information about unsuccessful subscriptions.- Type
list[
MultiSubscribeError]
- class twitchio.MultiSubscribeSuccess¶
A special
typing.NamedTuplecontaining two fields available in theMultiSubscribePayload, when a subscription to a Conduit is made successfully viamulti_subscribe().- subscription¶
The subscription payload passed to
multi_subscribe()which was successfully subscribed to.- Type
- class twitchio.MultiSubscribeError¶
A special
typing.NamedTuplecontaining two fields available in theMultiSubscribePayload, when a subscription to a Conduit is attempted viamulti_subscribe()and fails.- subscription¶
The subscription payload passed to
multi_subscribe()which failed.- Type
- error¶
The
HTTPExceptioncontaining various information, caught while attempting to subscribe to this subscription.- Type
TwitchIO - Documentation