DEV Community

0xwolfsync
0xwolfsync

Posted on • Originally published at tik-sync.com

How to Get TikTok Live Events in Python — Gifts, Chat, Follows

Summary — This tutorial walks you through connecting to any TikTok Live stream and receiving real-time events (gifts, chat messages, follows, shares, likes) using Python and the TikSync SDK. You'll go from zero to a working script in under 5 minutes — no headless browser, no proxy, no CAPTCHA.

Why TikSync Instead of TikTokLive?

If you've searched for "tiktok live python" before, you've probably found the open-source TikTokLive library. It works — sometimes. Under the hood, it relies on scraping TikTok's web page, which means it breaks every time TikTok updates their frontend, triggers CAPTCHAs on servers, and consumes hundreds of megabytes of RAM if it spins up a headless browser.

TikSync takes a fundamentally different approach. Instead of scraping, it uses a sign-only architecture built on 4 months of reverse engineering TikTok's binary protocol. Your Python script connects directly to TikTok's WebSocket servers using a cryptographic signature generated by TikSync's API — no browser, no proxy, no middleman for your data.

Feature TikTokLive (open-source) TikSync
First event 10+ seconds ~1-2 seconds
RAM usage 300-500 MB ~15 MB
CAPTCHA issues Frequent on servers Never
Breaks on TikTok updates Regularly Handled server-side
Event types ~10 18+

The best part: TikSync has a free tier with 1,000 API requests/day and 10 concurrent WebSocket connections. More than enough to build and test your project.

Installation

pip install tiksync
Enter fullscreen mode Exit fullscreen mode

That's it. No Chromium download, no system dependencies. Works on Windows, macOS, and Linux.

You'll also need a TikSync API key. Grab one for free at tik-sync.com — it takes about 30 seconds.

Quick Start

from tiksync import TikSync

client = TikSync(api_key="your_api_key")

@client.on("chat")
def on_chat(event):
    print(f"{event.user.nickname}: {event.comment}")

client.connect("username")  # TikTok @username (without the @)
Enter fullscreen mode Exit fullscreen mode

Run it, and you'll see live chat messages appearing in your terminal in real time.

Listening to Events

Chat Messages

@client.on("chat")
def on_chat(event):
    print(f"{event.user.nickname}: {event.comment}")
Enter fullscreen mode Exit fullscreen mode

Gifts

@client.on("gift")
def on_gift(event):
    if event.repeat_end:
        total_coins = event.diamond_count * event.repeat_count
        print(f"{event.user.nickname} sent {event.gift_name} x{event.repeat_count} ({total_coins} coins)")
Enter fullscreen mode Exit fullscreen mode

Follows

@client.on("follow")
def on_follow(event):
    print(f"New follower: {event.user.nickname}")
Enter fullscreen mode Exit fullscreen mode

Shares, Likes, and Joins

@client.on("share")
def on_share(event):
    print(f"{event.user.nickname} shared the stream!")

@client.on("like")
def on_like(event):
    print(f"{event.user.nickname} liked ({event.total_likes} total)")

@client.on("member")
def on_member(event):
    print(f"{event.user.nickname} joined the stream")
Enter fullscreen mode Exit fullscreen mode

Gift Tracking Example

from tiksync import TikSync
from collections import defaultdict

client = TikSync(api_key="your_api_key")
gift_totals = defaultdict(int)

@client.on("gift")
def on_gift(event):
    if event.repeat_end:
        coins = event.diamond_count * event.repeat_count
        gift_totals[event.user.unique_id] += coins
        print(f"[GIFT] {event.user.nickname} sent {event.gift_name} x{event.repeat_count} = {coins} coins")

@client.on("disconnect")
def on_disconnect():
    print("\nTop gifters this session:")
    for uid, total in sorted(gift_totals.items(), key=lambda x: -x[1])[:10]:
        print(f"  @{uid}: {total} coins")

client.connect("username")
Enter fullscreen mode Exit fullscreen mode

Going to Production

Automatic Reconnection

client = TikSync(
    api_key="your_api_key",
    reconnect=True,
    reconnect_interval=5,
    max_reconnect_attempts=0  # unlimited
)
Enter fullscreen mode Exit fullscreen mode

Async Support

import asyncio
from tiksync import AsyncTikSync

async def main():
    client = AsyncTikSync(api_key="your_api_key")

    @client.on("chat")
    async def on_chat(event):
        print(f"{event.user.nickname}: {event.comment}")

    await client.connect("username")

asyncio.run(main())
Enter fullscreen mode Exit fullscreen mode

What You Can Build

  • Chat bots that respond to commands in real time
  • Gift leaderboards and alert systems
  • Stream analytics dashboards
  • Interactive games controlled by viewers
  • Moderation tools
  • Integrations with Discord, Twitch, OBS

TikSync's Python SDK handles all the complexity of TikTok's protocol so you can focus on building your product.


*Originally published at [tik-sync.com/blog/how-to-get-tiktok-live-events-python](https://tik-sync.com/blog/how-to-get-tiktok-live-events-python

Top comments (0)