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

author: ClassVar[User]

The author of the comment

id: str

The id of the comment

likes_count: int

The amount of likes of the comment

parent: ClassVar[TikTokApi]
async replies(count=20, cursor=0, **kwargs) Iterator[Comment][source]
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
parent: ClassVar[TikTokApi]
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

Hashtags

TikTokApi.api.hashtag module

class TikTokApi.api.hashtag.Hashtag(name: str | None = None, id: str | None = None, data: dict | None = None)[source]

Bases: object

A TikTok Hashtag/Challenge.

Example Usage
hashtag = api.hashtag(name='funny')
async for video in hashtag.videos():
    print(video.id)
as_dict: dict

The raw data associated with this hashtag.

id: str | None

The ID of the hashtag

async info(**kwargs) dict[source]

Returns all information sent by TikTok related to this hashtag.

Example Usage
hashtag = api.hashtag(name='funny')
hashtag_data = await hashtag.info()
name: str | None

The name of the hashtag (omiting the #)

parent: ClassVar[TikTokApi]
async videos(count=30, cursor=0, **kwargs) Iterator[Video][source]

Returns TikTok videos that have this hashtag in the caption.

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.hashtag(name='funny').videos():
    # 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')
author: User | None

The author of the song (if it exists)

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.

parent: ClassVar[TikTokApi]
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.

author: User | None

The User who created the 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

hashtags: list[Hashtag] | None

A List of Hashtags on 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()
parent: ClassVar[TikTokApi]
async related_videos(count: int = 30, cursor: int = 0, **kwargs) Iterator[Video][source]

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

```

sound: Sound | None

The Sound that is associated with the Video

stats: dict | None

TikTok’s stats of the Video

url: str | None

The URL of the Video