Skip to main content

Connection Properties

unique_id

@property
def unique_id(self) -> str
The cleaned unique_id (username) that was passed to the client. Type: str Example:
client = TikTokLiveClient(unique_id="@username")
print(client.unique_id)  # Output: "username"

room_id

@property
def room_id(self) -> Optional[int]
The room ID the client is currently connected to. Returns None if not connected. Type: Optional[int] Example:
client = TikTokLiveClient(unique_id="@username")
await client.start()

print(client.room_id)  # Output: 7318070890374392602

connected

@property
def connected(self) -> bool
Whether the WebSocket client is currently connected to TikTok. Type: bool Example:
client = TikTokLiveClient(unique_id="@username")

print(client.connected)  # Output: False

await client.start()
print(client.connected)  # Output: True

await client.disconnect()
print(client.connected)  # Output: False

Client Objects

web

@property
def web(self) -> TikTokWebClient
The HTTP client that this client uses for requests to TikTok. Type: TikTokWebClient Example:
client = TikTokLiveClient(unique_id="@username")

# Access the underlying HTTP client
web_client = client.web

# Use web client methods
room_info = await web_client.fetch_room_info()

logger

@property
def logger(self) -> logging.Logger
The internal logger used by TikTokLive for debugging and error reporting. Type: logging.Logger Example:
import logging

client = TikTokLiveClient(unique_id="@username")

# Set log level
client.logger.setLevel(logging.DEBUG)

# Add custom handler
handler = logging.StreamHandler()
client.logger.addHandler(handler)

Stream Information

room_info

@property
def room_info(self) -> Optional[dict]
Information about the room. Only available if fetch_room_info=True was passed when starting the client (e.g., with client.run() or client.start()). Type: Optional[dict] Example:
client = TikTokLiveClient(unique_id="@username")

# Fetch room info on connection
await client.start(fetch_room_info=True)

# Access room information
if client.room_info:
    print(f"Room title: {client.room_info.get('title')}")
    print(f"Viewer count: {client.room_info.get('user_count')}")
Room Info Structure: The room_info dictionary typically contains:
  • title - The livestream title
  • user_count - Current viewer count
  • stats - Stream statistics
  • owner - Information about the streamer
  • And more…

gift_info

@property
def gift_info(self) -> Optional[dict]
Information about the stream’s available gifts. Only available if fetch_gift_info=True was passed when starting the client (e.g., with client.run() or client.start()). Type: Optional[dict] Example:
client = TikTokLiveClient(unique_id="@username")

# Fetch gift info on connection
await client.start(fetch_gift_info=True)

# Access gift information
if client.gift_info:
    for gift_id, gift_data in client.gift_info.items():
        print(f"Gift: {gift_data.get('name')} - {gift_data.get('diamond_count')} diamonds")
Gift Info Structure: The gift_info dictionary maps gift IDs to gift data objects containing:
  • name - The gift name
  • diamond_count - Cost in diamonds
  • image - Gift image URLs
  • type - Gift type/category
  • And more…

Usage Example

from TikTokLive import TikTokLiveClient
from TikTokLive.events import ConnectEvent

client = TikTokLiveClient(unique_id="@username")

@client.on(ConnectEvent)
async def on_connect(event: ConnectEvent):
    print(f"Connected to @{client.unique_id}")
    print(f"Room ID: {client.room_id}")
    print(f"Connected: {client.connected}")
    
    if client.room_info:
        print(f"Stream Title: {client.room_info.get('title')}")
    
    if client.gift_info:
        print(f"Available Gifts: {len(client.gift_info)}")

if __name__ == "__main__":
    client.run(
        fetch_room_info=True,
        fetch_gift_info=True
    )

Build docs developers (and LLMs) love