Overview
The Streaming API allows you to receive real-time updates for tweet engagements, direct message events, and typing indicators. This is useful for building live dashboards, notification systems, or monitoring tweet performance in real-time.StreamingSession
Represents an active streaming session that receives real-time events from Twitter.Attributes
The unique identifier of the streaming session.
The set of topics currently being streamed.
Whether the session automatically reconnects when disconnected.
Methods
reconnect()
Reconnects the streaming session if it gets disconnected.tuple[str, Payload] - The configuration event after reconnection.
update_subscriptions()
Updates the topics you’re subscribed to in an active streaming session.Topics to subscribe to.
Topics to unsubscribe from.
DM update and DM typing topics cannot be added dynamically after session creation.
Payload - The subscription update confirmation.
Payload
A named tuple containing various event types received from the streaming API.Attributes
Configuration event containing session information.
Event containing subscription status and errors.
Event containing tweet engagement metrics updates.
Event indicating a new direct message.
Event indicating someone is typing in a DM conversation.
Event Types
ConfigEvent
Event containing streaming session configuration.The session ID for this streaming connection.
The time-to-live for subscriptions in milliseconds.
The heartbeat interval in milliseconds.
SubscriptionsEvent
Event representing subscription status updates.List of errors that occurred during subscription updates.
TweetEngagementEvent
Event containing real-time tweet engagement metrics.The updated number of likes on the tweet.
The updated number of retweets.
The updated number of views.
The state of the view count.
The updated number of quote tweets.
The updated number of replies.
DMUpdateEvent
Event indicating a direct message update.The ID of the conversation where the message was sent.
The ID of the user who sent the message.
DMTypingEvent
Event indicating typing activity in a DM conversation.The ID of the conversation where typing is occurring.
The ID of the user who is typing.
Topic
Utility class for generating topic strings for streaming subscriptions.tweet_engagement()
Generates a topic string for streaming tweet engagement events.The ID of the tweet to monitor.
str - Topic string in format /tweet_engagement/{tweet_id}
dm_update()
Generates a topic string for streaming direct message updates.The ID of the conversation. Can be a group ID (
00000000) or partner-user format (00000000-00000001).str - Topic string in format /dm_update/{conversation_id}
dm_typing()
Generates a topic string for streaming typing indicators.The ID of the conversation. Can be a group ID (
00000000) or partner-user format (00000000-00000001).str - Topic string in format /dm_typing/{conversation_id}
