TikTok LIVE API for Python: Real-Time Livestream Events (Unofficial)
TikTok LIVE API (TikTokLive) is the #1 TikTok LIVE client for Python. Connect to any TikTok LIVE stream and receive real-time chat messages, gifts, likes, follows, shares, viewer counts, battles, and more using just a creator's @unique_id. No login, no credentials or app are required.
TikTokLive is the definitive third-party Python library for reading the TikTok LIVE websocket, building TikTok chat bots, gift trackers, live stream overlays, alerts, and analytics tools.
Note: This is not a production-ready API. It is a reverse engineering project. Use the WebSocket API for production by Euler Stream.
What Can You Build With the TikTok LIVE API?
- TikTok live chat readers and chat bots that respond to comments in real time
- Gift trackers and donation alerts for TikTok LIVE streamers (with streak handling)
- OBS overlays and stream widgets driven by live TikTok events
- TikTok LIVE analytics: viewer counts, likes, follows, battle (PK) scores
- Moderation tools that react to deleted messages and room events
- Text-to-speech (TTS) readers and interactive livestream games
TikTok LIVE API for Production
Table of Contents
- Getting Started
- Events
- Documentation
- Other Languages
- Community
- Examples
- FAQ
- Licensing
- Star History
- Contributors
Community
Join the TikTokLive discord and visit
the #py-support
channel for questions, contributions and ideas.
Getting Started
Install the TikTok LIVE API client for Python via pip from the PyPi repository:
pip install TikTokLive
Then create your first real-time TikTok LIVE chat connection:
from TikTokLive import TikTokLiveClient
from TikTokLive.events import ConnectEvent, CommentEvent
# Create the client
client: TikTokLiveClient = TikTokLiveClient(unique_id="@isaackogz")
# Listen to an event with a decorator!
@client.on(ConnectEvent)
async def on_connect(event: ConnectEvent):
print(f"Connected to @{event.unique_id} (Room ID: {client.room_id}")
# Or, add it manually via "client.add_listener()"
async def on_comment(event: CommentEvent) -> None:
print(f"{event.user.nickname} -> {event.comment}")
client.add_listener(CommentEvent, on_comment)
if __name__ == '__main__':
# Run the client and block the main thread
# await client.start() to run non-blocking
client.run()
For more quickstart examples, including a TikTok live chat reader, gift tracker, and live status checker, see the examples folder provided in the source tree.
TikTok LIVE API in Other Languages: Node.js, Java, C#, Go, Rust
The TikTokLive TikTok LIVE API is available in several alternate programming languages:
- Node.JS / JavaScript / TypeScript: TikTok-Live-Connector
- Java: TikTok-Live-Java
- C# / Unity: TikTokLiveSharp
- Go: gotiktoklive
- Rust: TikTokLiveRust
Parameters
| Param Name | Required | Default | Description |
|---|---|---|---|
| unique_id | Yes | N/A | The unique username of the broadcaster. You can find this name in the URL of the user. For example, the unique_id for https://www.tiktok.com/@isaackogz would be isaackogz. |
| web_proxy | No | None |
TikTokLive supports proxying HTTP requests. This parameter accepts an httpx.Proxy. Note that if you do use a proxy you may be subject to reduced connection limits at times of high load. |
| ws_proxy | No | None |
TikTokLive supports proxying the websocket connection. This parameter accepts an httpx.Proxy. Using this proxy will never be subject to reduced connection limits. |
| web_kwargs | No | {} |
Under the scenes, the TikTokLive HTTP client uses the httpx library. Arguments passed to web_kwargs will be forward the the underlying HTTP client. |
| ws_kwargs | No | {} |
Under the scenes, TikTokLive uses the websockets library to connect to TikTok. Arguments passed to ws_kwargs will be forwarded to the underlying WebSocket client. |
Methods
A TikTokLiveClient object contains the following methods worth mentioning:
| Method Name | Notes | Description |
|---|---|---|
| run | N/A | Connect to the livestream and block the main thread. This is best for small scripts. |
| add_listener | N/A | Adds an asynchronous listener function (or, you can decorate a function with @client.on(Type[Event])) and takes two parameters, an event name and the payload, an AbstractEvent |
| connect | async |
Connects to the tiktok live chat while blocking the current future. When the connection ends (e.g. livestream is over), the future is released. |
| start | async |
Connects to the live chat without blocking the main thread. This returns an asyncio.Task object with the client loop. |
| disconnect | async |
Disconnects the client from the websocket gracefully, processing remaining events before ending the client loop. |
Properties
A TikTokLiveClient object contains the following important properties:
| Attribute Name | Description |
|---|---|
| room_id | The Room ID of the livestream room the client is currently connected to. |
| web | The TikTok HT |
