TikTokAPI is an unofficial TikTok API for Python that pulls public TikTok data like trending videos, hashtags, users, sounds, and comments, no official API access needed (TikTok doesn’t offer one for most of this anyway). I built it in 2019 because researchers and developers had no real way to get data out of TikTok, and I’ve maintained it ever since.
Quickstart
pip install TikTokApi
python -m playwright installfrom TikTokApi import TikTokApi
import asyncio
import os
ms_token = os.environ.get("ms_token", None)
async def trending_videos():
async with TikTokApi() as api:
await api.create_sessions(ms_tokens=[ms_token], num_sessions=1, sleep_after=3, browser=os.getenv("TIKTOK_BROWSER", "chromium"))
async for video in api.trending.videos(count=30):
print(video)
print(video.as_dict)
if __name__ == "__main__":
asyncio.run(trending_videos())Full setup instructions, examples for every endpoint, and the API reference are in the GitHub repository and the documentation site.
What you can do with TikTokAPI
- Academic research: collect video, hashtag, and comment data at scale for studies on algorithms, misinformation, and online communities
- Trend tracking: monitor trending videos, sounds, and hashtags from a script instead of browsing manually
- Brand and social monitoring: track mentions, creator activity, and engagement around specific accounts or topics
- Content analysis: pull structured metadata (views, likes, shares, timestamps) into datasets for ML pipelines or dashboards
- Journalism and OSINT: investigate platform behavior with reproducible, scriptable data collection
Adoption
TikTokAPI has over 3 million downloads, 7.4K+ stars on GitHub, and 250+ companies using it or a derivative of it. It’s cited in 26+ peer-reviewed papers, including research from Yale, Northwestern, and a UNESCO (United Nations) publication, and organizations like tracking.exposed have built research on top of it. TikTok actively tries to block this kind of data collection, so for an unofficial library that level of adoption says a lot.
Academic citations
Researchers cite TikTokAPI because it’s often the only practical way to collect TikTok data at scale. Here are the peer-reviewed papers and books I’ve found on Google Scholar that use or cite the library. If you know of others, let me know.
- The TikTok Self: Music, Signaling, and Identity on Social Media (Yale)
- #TulsaFlop: A Case Study of Algorithmically-Influenced Collective Action on TikTok (Northwestern)
- History under attack: Holocaust denial and distortion on social media (Book, United Nations UNESCO)
- The recontextualisation of Multicultural London English: Stylising the ‘roadman’ (Book, University of Edinburgh)
- From #Dr00gtiktok to #harmreduction: Exploring Substance Use Hashtags on TikTok (Drexel University)
- #Pragmatic or #Clinical: Analyzing TikTok Mental Health Videos (University of Minnesota)
- The Platformization of TikTok: Examining TikTok’s Boundary Resources (The University of Toronto)
- When Kids Mode Isn’t For Kids: Investigating TikTok’s “Under 13 Experience” (University of California, Irvine)
- User Experiences with Abortion Misinformation on TikTok: Encounters, Assessment Strategies, and Response (DePaul University)
- Counting How the Seconds Count: Understanding Algorithm-User Interplay in TikTok via ML-driven Analysis of Video Content (University of Illinois Urbana-Champaign)
Undergraduate Papers
- Undergrad Paper Using Social Media to Predict which TV Shows will be Popular (Worchester Polytechnic Institute)
- Does Tiktok show viewers the content relevant to them? (University of California, Berkeley)
How it works: defeating TikTok’s bot detection
Scraping TikTok is harder than scraping most websites. TikTok signs its API requests with security parameters generated by obfuscated JavaScript, and it fingerprints clients pretty aggressively to catch automation (headless browsers, missing browser APIs, timing anomalies, etc). If you just send a plain HTTP request to their endpoints it gets rejected.
TikTokAPI gets around this by running a real browser session with Playwright in the background to generate valid security parameters, and patching the things that give away an automated browser. It’s a cat and mouse game. TikTok’s engineers watch the repository and patch the techniques it relies on, so the library has to keep evolving with each round of countermeasures. The whole point of the package is to hide all of that so you can write a few lines of Python and get structured data back.
I also wrote about the broader questions this kind of work raises in Is Web Scraping Ethical?, which draws a lot on my experience maintaining this library.
A personal note
I started this project in high school and it’s shaped my career more than anything else I’ve built. The reverse engineering skills I picked up maintaining it led directly to my security research, and seeing researchers at Yale, Northwestern, and the UN cite my code showed me open-source work can matter well beyond download counts. I’m grateful to the community that’s grown around the project and keeps it going.