TikTokApi.api package
This package wraps each entity from TikTok into a class with high-level methods to interact with the TikTok object.
Comment
TikTokApi.api.comment module
- class TikTokApi.api.comment.Comment(data: dict | None = None)[source]
Bases:
object
A TikTok Comment.
- Example Usage
for comment in video.comments: print(comment.text) print(comment.as_dict)
- as_dict: dict
The raw data associated with this comment
- id: str
The id of the comment
- likes_count: int
The amount of likes of the comment
- text: str
The contents of the comment
User
TikTokApi.api.user module
- class TikTokApi.api.user.User(username: str | None = None, user_id: str | None = None, sec_uid: str | None = None, data: dict | None = None)[source]
Bases:
object
A TikTok User.
- Example Usage:
user = api.user(username='therock')
- as_dict: dict
The raw data associated with this user.
- async info(**kwargs) dict [source]
Returns a dictionary of information associated with this User.
- Returns:
A dictionary of information associated with this User.
- Return type:
dict
- Raises:
InvalidResponseException – If TikTok returns an invalid response, or one we don’t understand.
- Example Usage:
user_data = await api.user(username='therock').info()
- async liked(count: int = 30, cursor: int = 0, **kwargs) Iterator[Video] [source]
Returns a user’s liked posts if public.
- Parameters:
count (int) – The amount of recent likes you want returned.
cursor (int) – The the offset of likes from 0 you want to get.
- Returns:
Yields TikTokApi.video objects.
- Return type:
async iterator/generator
- Raises:
InvalidResponseException – If TikTok returns an invalid response, the user’s likes are private, or one we don’t understand.
- Example Usage:
async for like in api.user(username="davidteathercodes").liked(): # do something
- async playlists(count=20, cursor=0, **kwargs) Iterator[dict] [source]
Returns a dictionary of information associated with this User’s playlist.
- Returns:
A dictionary of information associated with this User’s playlist.
- Return type:
dict
- Raises:
InvalidResponseException – If TikTok returns an invalid response, or one we don’t understand.
- Example Usage:
user_data = await api.user(username='therock').playlist()
- sec_uid: str
The sec UID of the user.
- user_id: str
The ID of the user.
- username: str
The username of the user.
- async videos(count=30, cursor=0, **kwargs) Iterator[Video] [source]
Returns a user’s videos.
- Parameters:
count (int) – The amount of videos you want returned.
cursor (int) – The the offset of videos from 0 you want to get.
- Returns:
Yields TikTokApi.video objects.
- Return type:
async iterator/generator
- Raises:
InvalidResponseException – If TikTok returns an invalid response, or one we don’t understand.
- Example Usage:
async for video in api.user(username="davidteathercodes").videos(): # do something
Trending
TikTokApi.api.trending module
- class TikTokApi.api.trending.Trending[source]
Bases:
object
Contains static methods related to trending objects on TikTok.
- static videos(count=30, **kwargs) Iterator[Video] [source]
Returns Videos that are trending on TikTok.
- Parameters:
count (int) – The amount of videos you want returned.
- Returns:
Yields TikTokApi.video objects.
- Return type:
async iterator/generator
- Raises:
InvalidResponseException – If TikTok returns an invalid response, or one we don’t understand.
- Example Usage:
async for video in api.trending.videos(): # do something
Search
TikTokApi.api.search module
- class TikTokApi.api.search.Search[source]
Bases:
object
Contains static methods about searching TikTok for a phrase.
- static search_type(search_term, obj_type, count=10, cursor=0, **kwargs) Iterator [source]
Searches for a specific type of object. But you shouldn’t use this directly, use the other methods.
Note: Your ms_token needs to have done a search before for this to work. Note: Currently only supports searching for users, other endpoints require auth.
- Parameters:
search_term (str) – The phrase you want to search for.
obj_type (str) – The type of object you want to search for (user)
count (int) – The amount of users you want returned.
cursor (int) – The the offset of users from 0 you want to get.
- Returns:
Yields TikTokApi.video objects.
- Return type:
async iterator/generator
- Raises:
InvalidResponseException – If TikTok returns an invalid response, or one we don’t understand.
- Example Usage:
async for user in api.search.search_type('david teather', 'user'): # do something
- static users(search_term, count=10, cursor=0, **kwargs) Iterator[User] [source]
Searches for users.
Note: Your ms_token needs to have done a search before for this to work.
- Parameters:
search_term (str) – The phrase you want to search for.
count (int) – The amount of users you want returned.
- Returns:
Yields TikTokApi.user objects.
- Return type:
async iterator/generator
- Raises:
InvalidResponseException – If TikTok returns an invalid response, or one we don’t understand.
- Example Usage:
async for user in api.search.users('david teather'): # do something
Sound
TikTokApi.api.sound module
- class TikTokApi.api.sound.Sound(id: str | None = None, data: str | None = None)[source]
Bases:
object
A TikTok Sound/Music/Song.
- Example Usage
song = api.song(id='7016547803243022337')
- duration: int | None
The duration of the song in seconds.
- id: str
TikTok’s ID for the sound
- async info(**kwargs) dict [source]
Returns all information sent by TikTok related to this sound.
- Returns:
The raw data returned by TikTok.
- Return type:
dict
- Raises:
InvalidResponseException – If TikTok returns an invalid response, or one we don’t understand.
- Example Usage:
sound_info = await api.sound(id='7016547803243022337').info()
- original: bool | None
Whether the song is original or not.
- title: str | None
The title of the song.
- async videos(count=30, cursor=0, **kwargs) Iterator[Video] [source]
Returns Video objects of videos created with this sound.
- Parameters:
count (int) – The amount of videos you want returned.
cursor (int) – The the offset of videos from 0 you want to get.
- Returns:
Yields TikTokApi.video objects.
- Return type:
async iterator/generator
- Raises:
InvalidResponseException – If TikTok returns an invalid response, or one we don’t understand.
- Example Usage:
async for video in api.sound(id='7016547803243022337').videos(): # do something
Video
TikTokApi.api.video module
- class TikTokApi.api.video.Video(id: str | None = None, url: str | None = None, data: dict | None = None, **kwargs)[source]
Bases:
object
A TikTok Video class
Example Usage
`py video = api.video(id='7041997751718137094') `
- as_dict: dict
The raw data associated with this Video.
- async bytes(stream: bool = False, **kwargs) bytes | AsyncIterator[bytes] [source]
Returns the bytes of a TikTok Video.
- Example Usage:
video_bytes = await api.video(id='7041997751718137094').bytes() # Saving The Video with open('saved_video.mp4', 'wb') as output: output.write(video_bytes) # Streaming (if stream=True) async for chunk in api.video(id='7041997751718137094').bytes(stream=True): # Process or upload chunk
- async comments(count=20, cursor=0, **kwargs) Iterator[Comment] [source]
Returns the comments of a TikTok Video.
- Parameters:
count (int) – The amount of comments you want returned.
cursor (int) – The the offset of comments from 0 you want to get.
- Returns:
Yields TikTokApi.comment objects.
- Return type:
async iterator/generator
Example Usage .. code-block:: python
- async for comment in api.video(id=’7041997751718137094’).comments():
# do something
- create_time: datetime | None
The creation time of the Video
- id: str | None
TikTok’s ID of the Video
- async info(**kwargs) dict [source]
Returns a dictionary of all data associated with a TikTok Video.
Note: This is slow since it requires an HTTP request, avoid using this if possible.
- Returns:
A dictionary of all data associated with a TikTok Video.
- Return type:
dict
- Raises:
InvalidResponseException – If TikTok returns an invalid response, or one we don’t understand.
- Example Usage:
url = "https://www.tiktok.com/@davidteathercodes/video/7106686413101468970" video_info = await api.video(url=url).info()
Returns related videos of a TikTok Video.
- Parameters:
count (int) – The amount of comments you want returned.
cursor (int) – The the offset of comments from 0 you want to get.
- Returns:
Yields TikTokApi.video objects.
- Return type:
async iterator/generator
Example Usage .. code-block:: python
- async for related_videos in api.video(id=’7041997751718137094’).related_videos():
# do something
- stats: dict | None
TikTok’s stats of the Video
- url: str | None
The URL of the Video