Skip to main content

Overview

The TikTokLiveClient class is the main entry point for connecting to and reading from TikTok LIVE streams. It extends AsyncIOEventEmitter and provides a simple interface for listening to real-time events from TikTok livestreams.

Constructor

TikTokLiveClient(
    unique_id: str | int,
    platform: WebcastPlatform = WebcastPlatform.WEB,
    web_proxy: Optional[httpx.Proxy] = None,
    ws_proxy: Optional[WebcastProxy] = None,
    web_kwargs: Optional[dict] = None,
    ws_kwargs: Optional[dict] = None,
    is_user_id: Optional[bool] = False
)

Parameters

unique_id
str | int
required
The username of the TikTok creator to connect to. Can also be a user ID if is_user_id=True.
platform
WebcastPlatform
default:"WebcastPlatform.WEB"
The platform to use for the webcast connection. Defaults to web platform.
web_proxy
httpx.Proxy
default:"None"
An optional proxy used for HTTP requests to TikTok.
ws_proxy
WebcastProxy
default:"None"
An optional proxy used for the WebSocket connection.
web_kwargs
dict
default:"None"
Optional arguments passed to the HTTP client for additional configuration.
ws_kwargs
dict
default:"None"
Optional arguments passed to the WebSocket client for additional configuration.
is_user_id
bool
default:"False"
When True, resolves the numeric user ID to a unique_id username.

Basic Usage

from TikTokLive import TikTokLiveClient
from TikTokLive.events import CommentEvent

# Create client instance
client = TikTokLiveClient(unique_id="@username")

# Add event listeners
@client.on(CommentEvent)
async def on_comment(event: CommentEvent):
    print(f"{event.user.nickname}: {event.comment}")

# Connect to livestream
if __name__ == "__main__":
    client.run()

Advanced Usage

Using Proxies

import httpx
from TikTokLive import TikTokLiveClient

# Configure HTTP proxy
web_proxy = httpx.Proxy("http://proxy.example.com:8080")

client = TikTokLiveClient(
    unique_id="@username",
    web_proxy=web_proxy
)

Connecting by Room ID

client = TikTokLiveClient(unique_id="@username")

# Connect directly with room ID (skips HTML scraping)
await client.start(room_id=7318070890374392602)

See Also

Build docs developers (and LLMs) love