Skip to main content

TikHub API Python SDK

GitHub Stars GitHub Forks GitHub Issues GitHub Pull Requests License

English | 中文 | Français | Español | 日本語

TikHub Banner

The official Python SDK for the TikHub social media data API — a unified REST API that provides real-time access to 16+ social media platforms including TikTok, Douyin, Instagram, YouTube, Twitter/X, Xiaohongshu (Red Note), Bilibili, Weibo, Threads, LinkedIn, Reddit, Kuaishou, WeChat, Lemon8, Zhihu, and more.

Built for developers, data scientists, and AI engineers who need structured social media data at scale — for AI training, influencer analytics, trend monitoring, sentiment analysis, market research, and competitive intelligence.

Why TikHub?

  • 1000+ endpoints across 16 platforms through a single API key
  • Real-time data — video details, user profiles, comments, search results, live streams, trending content, and e-commerce analytics
  • RESTful & OpenAPI-native — every endpoint is documented in the OpenAPI spec and testable via Swagger UI
  • MCP integration — connect AI agents (Claude, LangChain, Coze, n8n) directly to social media data via Model Context Protocol
  • Datasets available — 1B+ pre-collected, structured records for training and research

Why This SDK?

  • 100% endpoint coverage — 1048 / 1048 endpoints from OpenAPI spec V5.3.2 (deprecated endpoints excluded), mechanically generated and verified
  • Sync + async — TikHub and AsyncTikHub clients with identical APIs
  • Production-ready — automatic retries with exponential backoff, rate-limit handling, structured error hierarchy with full debugging context
  • Type-safe — mypy --strict clean, built on httpx + pydantic v2
  • Zero config — flat kwargs, no config objects; set one env var and go

Version: 2.1.1 — Requires Python 3.9+

Supported Platforms

Platform Resource Endpoints
TikTok tiktok_web, tiktok_app_v3, tiktok_creator, tiktok_analytics, tiktok_ads, tiktok_shop_web 162
Douyin douyin_web, douyin_app_v3, douyin_search, douyin_billboard, douyin_creator, douyin_creator_v2, douyin_xingtu, douyin_xingtu_v2, douyin_index, douyin_douplus 319
Instagram instagram_v1, instagram_v2, instagram_v3 93
YouTube youtube_web, youtube_web_v2 34
Twitter / X twitter_web 25
Xiaohongshu (Red Note) xiaohongshu_app_v2, xiaohongshu_web_v3, xiaohongshu_pgy 45
Bilibili bilibili_web, bilibili_app, bilibili_huahuo 87
Weibo weibo_web_v2, weibo_app 56
Threads threads_web 12
LinkedIn linkedin_web_v2 8
Telegram telegram_web 7
Reddit reddit_app 28
Kuaishou kuaishou_web, kuaishou_app 38
WeChat wechat_channels_v2, wechat_media_platform_v2, wechat_search_v2 25
Lemon8 lemon8_app 16
Zhihu zhihu_web 41
Others toutiao_web, toutiao_app, xigua_app_v2, pipixia_app 31

Install

pip install tikhub

Requires Python 3.9+.

From source

git clone https://github.com/TikHub/TikHub-API-Python-SDK.git
cd TikHub-API-Python-SDK
pip install -e ".[dev]"
pytest -q

Get your API Key

  1. Go to https://user.tikhub.io/login and sign up / log in.
  2. Copy your API key from the dashboard.
  3. Set it as an environment variable or pass it directly:
export TIKHUB_API_KEY="YOUR_API_KEY"

Quickstart

from tikhub import TikHub

client = TikHub(api_key="YOUR_API_KEY")

# 1:1 with the OpenAPI spec — resource = tag, method = path basename
video = client.douyin_web.fetch_one_video(aweme_id="7251234567890123456")
print(video.aweme_detail.desc)

client.close()

Or with the recommended context manager:

with TikHub(api_key="YOUR_API_KEY") as client:
    health = client.health_check.check()
    print(health.status)

Async

import asyncio
from tikhub import AsyncTikHub

async def main():
    async with AsyncTikHub(api_key="YOUR_API_KEY") as client:
        video = await client.douyin_web.fetch_one_video(aweme_id="...")
        print(video.aweme_detail.desc)

asyncio.run(main())

Configuration

The constructor takes one required argument and a small handful of optional kwargs:

TikHub(
    api_key=None,        # str | None — defaults to $TIKHUB_API_KEY
    timeout=30,          # float | None — total request timeout in seconds
    base_url=None,       # str | None — only override for a private mirror

    # Advanced (rare):
    max_retries=3,
    proxy=None,
    user_agent=None,
    parse_response=True,
    http_client=None,    # bring your own httpx.Client
)

That's the entire configuration surface. There is no ClientConfig object — knobs are flat kwargs.

Naming rules

The SDK is mechanically derived from the TikHub OpenAPI spec. Two rules:

  1. Resource attribute = OpenAPI tag, lowercased, dashes → underscores, -API stripped. Douyin-Web-API → client.douyin_web. TikTok-App-V3-API → client.tiktok_app_v3.
  2. Method name = the last segment of the API path, verbatim. /api/v1/douyin/web/fetch_one_video → client.douyin_web.fetch_one_video(...).

Parameter names match the OpenAPI spec verbatim. If you can read the TikHub API docs, you already know how to use the SDK.

Status

100% endpoint coverage against TikHub OpenAPI spec V5.3.2.

Resources 51 (one per OpenAPI tag)
Endpoints 1048 / 1048
Tests 108 passing
Type-check mypy --strict clean across 70 source files
Lint ruff clean
Phase Scope State
0 Foundation: client, transport, errors, retries, pagination ✅ done
1 Codegen pipeline (scripts/refresh_spec.py, generate_resources.py, verify_coverage.py) ✅ done
2 Douyin + TikTok core (412 endpoints) ✅ done
3 Other Chinese platforms (302 endpoints) ✅ done
4 International platforms (234 endpoints) ✅ done
5 TikTok specialty + utilities (94 endpoints) ✅ done
6 Docs site, CLI, migration guide, release workflow ✅ done

The resource layer is mechanically generated from spec/openapi.json. To refresh after a TikHub spec update:

python scripts/refresh_spec.py        # pulls latest openapi.json, prints diff
python scripts/generate_resources.py  # regenerates all 51 resource files + clients
python scripts/generate_docs.py       # regenerates docs/reference.md
python scripts/verify_coverage.py     # asserts 100% coverage
pytest -q                             # 110 tests

CLI

A small console wrapper ships in the cli extra:

pip install "tikhub[cli]"
export TIKHUB_API_KEY="YOUR_API_KEY"

tikhub health                                 # ping the API
tikhub fetch https://v.douyin.com/abc/        # universal video URL parser
tikhub user info                              # plan + quota
tikhub user usage                             # today's request count

Every command prints JSON to stdout — pipe to jq or any other formatter.

Documentation

Full docs (mkdocs-material): authentication, async, errors, pagination, retries, logging, CLI, migration guide, naming rules, and the auto-generated reference for all 1048 endpoints.

pip install -e ".[docs]"
mkdocs serve            # http://127.0.0.1:8000

License

MIT.

Metadata

Release files for tikhub 2.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tikhub 2.2.0
File Size Uploaded
tikhub-2.2.0.tar.gz 121.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tikhub 2.2.0
File Interpreter ABI Platform
tikhub-2.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 274.6 kB

Release files / tikhub-2.2.0.tar.gz

Download URL tikhub-2.2.0.tar.gz
Size 121.8 kB
Tags Source
SHA-256 checksum
How to use checksums
1bb2d4ee9bc11b675915737481e84c7826d36fb52944ac7218d8203c316cbffc
BLAKE2b-256 checksum
How to use checksums
2e6ecaf80ce678137ab2c2a2dafca6f34ad12b0379f169069e15982e5d37acb2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 3, 2026.

Transparency log

Release files / tikhub-2.2.0-py3-none-any.whl

Download URL tikhub-2.2.0-py3-none-any.whl
Size 152.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5f61293494e0b3713ee4eddcdfa89ad5e19fe2b839cc0d2852925ac8030e4f67
BLAKE2b-256 checksum
How to use checksums
018ec795d51554d9538e0babdd017e23f5674cda9712cd580c7ad7d5661f3f53
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 3, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

2.2.0 This release

2 release files

2.1.2

2 release files

2.1.1

2 release files

2.1.0

2 release files

1.12.9

2 release files

1.12.8

2 release files

1.12.5

2 release files

1.12.0

2 release files

1.11.4

2 release files

1.11.3

2 release files

1.11.2

2 release files

1.11.1

2 release files

1.11.0

2 release files

1.10.9

2 release files

1.10.8

2 release files

1.10.7

2 release files

1.10.6

2 release files

1.10.1

2 release files

1.10.0

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page