Skip to main content

The Unofficial TikTok API Wrapper in Python 3.

Project description

Unofficial TikTok API in Python

This is an unofficial api wrapper for TikTok.com in python. With this api you are able to call most trending and fetch specific user information as well as much more.

DOI LinkedIn Sponsor Me GitHub release (latest by date) GitHub Downloads Support Server

This api is designed to retrieve data TikTok. It can not be used post or upload content to TikTok on the behalf of a user. It has no support for any user-authenticated routes, if you can't access it while being logged out on their website you can't access it here.

Sponsors

These sponsors have paid to be placed here or are my own affiliate links which I may earn a commission from, and beyond that I do not have any affiliation with them. The TikTokAPI package will always be free and open-source. If you wish to be a sponsor of this project check out my GitHub sponsors page.

TikApi
TikAPI is a paid TikTok API service providing a full out-of-the-box solution, making life easier for developers — trusted by 500+ companies.

Ensemble Data
EnsembleData is the leading API provider for scraping Tiktok, Instagram, Youtube, and more.
Trusted by the major influencer marketing and social media listening platforms.

TikHub API
TikHub API offers 700+ endpoints for fetching and analyzing data from 14+ social media platforms
including videos, users, comments, shops, products, and trends — all in one place.

Zernio
Zernio — Skip TikTok's API review process. Publish videos, schedule posts, manage comments, and pull analytics through our pre-approved TikTok integration. Works with 13 other platforms too.

SocialAPIs
SocialAPIs — Facebook data APIs that just work. Extract Pages, Groups, Posts, Reels, Comments, Ads Library & Marketplace via clean JSON endpoints. No proxies, no headless browsers. MCP included!

Webshare Proxies
Cheap, Reliable Proxies: Supercharge your web scraping with fast, reliable proxies. Try 10 free datacenter proxies today!

Table of Contents

Documentation

You can find the full documentation here

Getting Started

To get started using this API follow the instructions below.

Note: If you want to learn how to web scrape websites check my free and open-source course for learning everything web scraping

How to Support The Project

  • Star the repo 😎
  • Consider sponsoring me on GitHub
  • Send me an email or a LinkedIn message telling me what you're using the API for, I really like hearing what people are using it for.
  • Submit PRs for issues :)

Installing

Note: Installation requires python3.9+

If you run into an issue please check the closed issues on the github, although feel free to re-open a new issue if you find an issue that's been closed for a few months. The codebase can and does run into similar issues as it has before, because TikTok changes things up.

pip install TikTokApi
python -m playwright install

If you would prefer a video walk through of setting up this package YouTube video just for that. (is a version out of date, installation is the same though)

If you want a quick video to listen for TikTok Live events in python.

Docker Installation

Clone this repository onto a local machine (or just the Dockerfile since it installs TikTokApi from pip) then run the following commands.

docker pull mcr.microsoft.com/playwright:focal
docker build . -t tiktokapi:latest
docker run -v TikTokApi --rm tiktokapi:latest python3 your_script.py

Note this assumes your script is named your_script.py and lives in the root of this directory.

Common Issues

  • EmptyResponseException - this means TikTok is blocking the request and detects you're a bot. This can be a problem with your setup or the library itself

    • you may need a proxy to successfully scrape TikTok, I've made a web scraping lesson explaining the differences of "tiers" of proxies, I've personally had success with webshare's residential proxies (affiliate link), but you might have success on their free data center IPs or a cheaper competitor.
  • Browser Has no Attribute - make sure you ran python3 -m playwright install, if your error persists try the playwright-python quickstart guide and diagnose issues from there.

  • API methods returning Coroutine - many of the API's methods are async so make sure your program awaits them for proper functionality

Quick Start Guide

Here's a quick bit of code to get the most recent trending videos on TikTok. There's more examples in the examples directory.

Note: If you want to learn how to web scrape websites check my free and open-source course for web scraping

from TikTokApi import TikTokApi
import asyncio
import os

ms_token = os.environ.get("ms_token", None) # get your own ms_token from your cookies on tiktok.com

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())

To directly run the example scripts from the repository root, use the -m option on python.

python -m examples.trending_example

You can access the full data dictionary the object was created from with .as_dict. On a video this may look like this. TikTok changes their structure from time to time so it's worth investigating the structure of the dictionary when you use this package.

Project details


Release history Release notifications | RSS feed

This version

7.3.3

Download files

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

Source Distribution

tiktokapi-7.3.3.tar.gz (49.6 kB view details)

Uploaded Source

Built Distribution

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

tiktokapi-7.3.3-py3-none-any.whl (65.6 kB view details)

Uploaded Python 3

File details

Details for the file tiktokapi-7.3.3.tar.gz.

File metadata

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

File hashes

Hashes for tiktokapi-7.3.3.tar.gz
Algorithm Hash digest
SHA256 621d622cc5c6030b5287d92d89583a3e4e4330f39f21aa4a856e05af36cf689e
MD5 7a10d49719ce522589cb6372eeeb56b5
BLAKE2b-256 212ed88cf2cea38921086b768a81a673e226d136a3505fdced54d3b8c9a65cf9

See more details on using hashes here.

File details

Details for the file tiktokapi-7.3.3-py3-none-any.whl.

File metadata

  • Download URL: tiktokapi-7.3.3-py3-none-any.whl
  • Upload date:
  • Size: 65.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for tiktokapi-7.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2d7ef0ca20963b98d52907ec537bd73330e9ea4ffbb0f2587c9b9c7faf3ac3f0
MD5 254ce32a78b117171561b26e77f18de0
BLAKE2b-256 d44154a84ad9a55c452e54523c8c4b0b15314fe7d6e0c0b0465c2026f4a6d033

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