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.

GitHub release (latest by date) Build Status GitHub PyPI - Downloads Downloads

If you want to use this API as a service visit the RapidAPI

Consider sponsoring me here

Table of Contents

Getting Started

To get started using this api follow the instructions below.

Installing

If you run into an issue please check the closed issues on the github. You’re most likely not the first person to experience this issue. If nothing works feel free to open an issue.

pip install TikTokApi

The script should download pypppeteer by default, but if it doesn’t run the following command.

pyppeteer-install

If you still run into issues you may need to install chromedriver for your machine globally. Download it here and add it to your path.

Common Issues

Please don’t open an issue if you’re experiencing one of these just comment if the provided solution do not work for you.

Quick Start Guide

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

from TikTokApi import TikTokApi
api = TikTokApi()

results = 10

trending = api.trending(count=results)

for tiktok in trending:
    # Prints the text of the tiktok
    print(tiktok['desc'])

print(len(trending))

Here’s an example of what a tiktok dictionary looks like.

Detailed Documentation

Note: This documentation is called detailed, which it is, but it may be out of date. And if you see something wrong or want to improve the documentation feel free to open a PR with the fixes.

Common Parameters

The TikTok class
TikTokApi(self, debug=False)

debug - Enable this if you need some more output.

api.trending(self, count=30, referrer="https://www.tiktok.com/@ondymikula/video/6756762109670477061", language='en', proxy=None)

count - this is how many trending Tiktoks you want to be returned.

Trending returns an array of dictionaries. Example structure here

The get_Video_By_TikTok Method
api.get_Video_By_TikTok(data, language='en', proxy=None)

data - The tiktok dictionary returned from the API. Will return bytes.

The bySound Method

This method returns an array of tiktoks based on a sound id.

def bySound(self, id, count=30, language='en', proxy=None)

id - the sound’s id (you can get this from other methods)

The getUserObject Method

This method returns a user object, primarily used for other methods within the package.

def getUserObject(self, username, language='en', proxy=None)
The getTikTokById Method

This object returns a TikTok object when given the TikTok ID.

def getTikTokById(self, id, language='en', proxy=None)
The getTikTokByUrl Method

This does the same as the getTikTokById method, but it extracts the id out of the url.

def getTikTokByUrl(self, url, language='en', proxy=None)
The getUser Method

This method returns a user object, including all profile data about the user.

def getUser(self, username, language='en', proxy=None)

username - the unique username of the person you want to get an object for.

The getMusicObject Method

This method returns a music object, primarily used for other methods within the package.

def getMusicObject(self, id, language='en', proxy=None)

id - the ID of the music.

The getHashtagObject Method

This method returns a hashtag (challenge) object, primarily used for other methods within the package.

def getHashtagObject(self, hashtag, language='en', proxy=None)

hashtag - the hashtag or challenge name

The byUsername Method

This method returns an array of tiktoks by a username

def byUsername(self, username, count=30, language='en', proxy=None)
The byHashtag Method

This method returns an array of TikToks by a given hashtag or challenge (without the #)

def byHashtag(self, hashtag, count=30, language='en', proxy=None)

hashtag - a given hashtag or challenge without the #

The discoverMusic Method

Returns trending music shown on the side at tiktok’s trending page on desktop

def discoverMusic(self, language='en', proxy=None)
The discoverHashtags Method

Returns trending hashtags (challenges) shown on the side at tiktok’s trending page on desktop

def discoverHashtags(self, language='en', proxy=None)
The userLiked Method

Returns a list of a given user’s liked TikToks. Returns a length of 0 if private list.

userLiked(self, userID, secUID, count=30, language='en', region='US', proxy=None)

The userLikedbyUsername Method

Returns a list of a given user’s liked TikToks. Returns a length of 0 if private list.

userLikedbyUsername(self, username, count=30, proxy=None, language='en', region='US')
The getSuggestedUsersbyID Method

This method gets suggested users for a given userid.

getSuggestedUsersbyID(self, count=30, userId='6745191554350760966', language='en', proxy=None)
The getSuggestedUsersbyIDCrawler Method

This method gets users across a variety of userids.

getSuggestedUsersbyIDCrawler(self, count=30, startingId='6745191554350760966', language='en', proxy=None)
The getSuggestedHashtagsbyID Method

This method gets related hashtags given a userid.

getSuggestedHashtagsbyID(self, count=30, userId='6745191554350760966', language='en', proxy=None)
The getSuggestedHashtagsbyIDCrawler Method

This method crawls across multiple user’s profile using the user crawler method to generate hashtags.

getSuggestedHashtagsbyIDCrawler(self, count=30, startingId='6745191554350760966', language='en', proxy=None)
The getSuggestedMusicbyID Method

This method gets suggested music given a userId

getSuggestedMusicbyID(self, count=30, userId='6745191554350760966', language='en', proxy=None)
The getSuggestedMusicIDCrawler Method

This method crawls across multiple user’s profile using the user crawler method to generate music objects.

getSuggestedMusicIDCrawler(self, count=30, startingId='6745191554350760966', language='en', proxy=None)
The get_Video_By_DownloadURL Method
api.get_Video_By_DownloadURL(url, language='en', proxy=None)

url - The download url that’s found in the TikTok dictionary. TikTok[‘video’][‘downloadAddr’]

The get_Video_By_Url Method
api.get_Video_By_Url(video_url, return_bytes=0)

video_url - The video you want to get url.

return_bytes - The default value is 0, when it is set to 1 the function instead returns the bytes from the video rather than just the direct url.

The get_Video_No_Watermark Method
api.get_Video_No_Watermark(video_url, return_bytes=0, language='en', proxy=None)

video_url - The video you want to get url.

return_bytes - The default value is 0, when it is set to 1 the function instead returns the bytes from the video rather than just the direct url.

The get_Video_No_Watermark_ID Method
api.get_Video_No_Watermark_ID(self, video_id, return_bytes=1, proxy=None)

video_id - The video id you want to get.

return_bytes - The default value is 0, when it is set to 1 the function instead returns the bytes from the video rather than just the direct url.

Built With

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details