Skip to main content

TikTok Live WebSocket connector — real-time chat, gifts, likes, and viewer events. No authentication required.

Project description

PirateTok

piratetok-live-py

Connect to any TikTok Live stream and receive real-time events in Python. No signing server, no API keys, no authentication required.

import asyncio
from piratetok_live import TikTokLiveClient, EventType

async def main():
    # Create client — no API key, no signing server, just a username
    client = TikTokLiveClient("username_here")

    # Register handlers with decorators — events carry decoded protobuf data
    @client.on(EventType.chat)
    def on_chat(evt):
        nick = evt.data.get("user", {}).get("nickname", "?")
        print(f"[chat] {nick}: {evt.data.get('content')}")

    @client.on(EventType.gift)
    def on_gift(evt):
        nick = evt.data.get("user", {}).get("nickname", "?")
        gift = evt.data.get("gift", {})
        print(f"[gift] {nick} sent {gift.get('name')} x{evt.data.get('repeatCount')} ({gift.get('diamondCount', 0)} diamonds)")

    @client.on(EventType.like)
    def on_like(evt):
        nick = evt.data.get("user", {}).get("nickname", "?")
        print(f"[like] {nick} ({evt.data.get('totalLikes')} total)")

    # Connect — handles auth, room resolution, WSS, heartbeat, and reconnection
    await client.connect()

asyncio.run(main())

Install

pip install piratetok-live

Requires Python >= 3.11.

Other languages

Language Install Repo
Rust cargo add piratetok-live-rs live-rs
Go go get github.com/PirateTok/live-go live-go
JavaScript npm install piratetok-live-js live-js
C# dotnet add package PirateTok.Live live-cs
Java com.piratetok:live live-java
Lua luarocks install piratetok-live-lua live-lua
Elixir {:piratetok_live, "~> 0.1"} live-ex
Dart dart pub add piratetok_live live-dart
C #include "piratetok.h" live-c
PowerShell Install-Module PirateTok.Live live-ps1
Shell bpkg install PirateTok/live-sh live-sh

Features

  • Zero signing dependency — no API keys, no signing server, no external auth
  • 64 decoded event types — hand-written betterproto dataclasses, no codegen
  • Auto-reconnection — stale detection, exponential backoff, self-healing auth
  • Proxy support.proxy(url) builder, applies to HTTP + WSS
  • Enriched User data — badges, gifter level, moderator status, follow info, fan club
  • Sub-routed convenience eventsfollow, share, join, liveEnded
  • 2 runtime depsbetterproto + websockets

Configuration

client = (TikTokLiveClient("username_here")
    .cdn_eu()
    .timeout(15)
    .max_retries(10)
    .stale_timeout(90)
    .proxy("socks5://127.0.0.1:1080"))

Room info (optional, separate call)

from piratetok_live import check_online, fetch_room_info

result = check_online("username_here")
info = fetch_room_info(result.room_id)

# 18+ rooms
info = fetch_room_info(result.room_id, cookies="sessionid=abc; sid_tt=abc")

Examples

python examples/basic_chat.py <username>       # connect + print chat events
python examples/online_check.py <username>     # check if user is live
python examples/stream_info.py <username>      # fetch room metadata + stream URLs
python examples/gift_tracker.py <username>     # track gifts with diamond totals

Replay testing

Deterministic cross-lib validation against binary WSS captures. Requires testdata from a separate repo:

git clone https://github.com/PirateTok/live-testdata ../live-testdata
pip install -e ".[test]"
pytest tests/test_replay.py -v

Tests skip gracefully if testdata is not found. You can also set PIRATETOK_TESTDATA to point to a custom location.

License

0BSD

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

piratetok_live_py-0.1.4.tar.gz (28.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

piratetok_live_py-0.1.4-py3-none-any.whl (28.0 kB view details)

Uploaded Python 3

File details

Details for the file piratetok_live_py-0.1.4.tar.gz.

File metadata

  • Download URL: piratetok_live_py-0.1.4.tar.gz
  • Upload date:
  • Size: 28.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for piratetok_live_py-0.1.4.tar.gz
Algorithm Hash digest
SHA256 6a81061463fb3e06bbb189eef38b074f0b5ec63169c0d810c53d00dbbe3c1693
MD5 b1cea5ce758ac1309a130b4c6f8605bd
BLAKE2b-256 27ad3ba77963940dbfc993834e16ad30e3f0650dc4cad61ed0e0a36e29eab0d5

See more details on using hashes here.

File details

Details for the file piratetok_live_py-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for piratetok_live_py-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 aa8cbb73710c12955e5d897d5cbf57584a3eceaf244d1fcdc15d3471408b589b
MD5 aa7d6e74ff65479c8f164a46a13d82fd
BLAKE2b-256 6e2131f4ca595a0406bd501bc70a547f22c442f9a2e1a0cf8b4da7782030c137

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page