Introduction
The TikTokLive Python SDK provides a robust event system for handling real-time events from TikTok LIVE streams. Events are triggered when various actions occur during a livestream, such as comments, gifts, likes, and user interactions.Event Types
There are two main categories of events in TikTokLive:Custom Events
Custom events are manually triggered by the SDK for connection lifecycle management:- ConnectEvent - Fired when successfully connected to a stream
- DisconnectEvent - Fired when disconnecting from a stream
- LiveEndEvent - Fired when the livestream ends
- LivePauseEvent - Fired when the stream is paused
- LiveUnpauseEvent - Fired when a paused stream resumes
- FollowEvent - Fired when a user follows the streamer
- ShareEvent - Fired when a user shares the stream
- SuperFanEvent - Fired for super fan interactions
- UnknownEvent - Fired for untracked message types
- WebsocketResponseEvent - Fired for any WebSocket event
Proto Events
Proto events are generated from TikTok’s protocol buffers and represent real-time stream interactions. These include:- Chat & Comments - CommentEvent, EmoteChatEvent, ScreenChatEvent
- Gifts - GiftEvent, GiftUpdateEvent, GiftBroadcastEvent
- Engagement - LikeEvent, DiggEvent, JoinEvent
- Social - FollowEvent, ShareEvent, SocialEvent
- Room Updates - RoomEvent, RoomPinEvent, RoomNotifyEvent
- Battles & Games - LinkMicBattleEvent, GameMomentEvent
- And 200+ more event types…
Listening to Events
To handle events, use the@client.on() decorator:
Event Base Class
All events inherit fromBaseEvent, which provides common functionality and properties. Each event may have specific properties based on the event type.
Accessing Event Data
Most events provide structured data through properties:Error Handling
It’s recommended to wrap event handlers with try-except blocks:Next Steps
- Learn about Custom Events
- Explore Proto Events
- See the Client Reference for connection management