# How to Collect TikTok Data With Python

To collect TikTok data with Python, install apify-client, call apidojo's TikTok actors with your API token, and read each run's dataset.

[![apidojo](/blog/authors/apidojo.png)**Apidojo** *15+ years of experience in data retrieval.*](/blog/authors/apidojo/)

**12 October 2026** Published

**3 min** Read

![Cover card reading 'How to Collect TikTok Data With Python'](/blog/covers/tiktok-python.png)

**To collect TikTok data with Python, install `apify-client`, call apidojo’s TikTok actors with your API token, and read each run’s dataset.** One script can search videos by keyword, pull the comments on the best ones and save everything to CSV, with no TikTok login, proxies or developer approval.

This guide builds that script step by step: setup, a video search, chaining a comment scrape onto the results, cleaning the data and saving it. The actor choice for each data type is explained in [how to scrape TikTok data in 2026](/blog/tiktok-scraping/how-to-scrape-tiktok/).

## What Do You Need to Collect TikTok Data With Python?

**You need Python 3, the `apify-client` and `pandas` packages, and an Apify API token on a paid plan.** apidojo’s TikTok actors run in demo mode on the free plan, 5 runs a month with 10 items each ([Apify](https://apify.com/apidojo/tiktok-scraper)). Listed below are the 3 setup steps.

1.  **Install** the packages: `pip install apify-client pandas`.
2.  **Copy** your API token from Apify Console.
3.  **Store** it in an environment variable: `export APIFY_TOKEN=your_token`.

## How Do You Search TikTok Videos With Python?

**Call the TikTok Scraper actor with a `keywords` list and read the items from its dataset.** The input and field names come from the actor’s documentation (Apify).

```
import os
from apify_client import ApifyClient

client = ApifyClient(os.environ["APIFY_TOKEN"])

run = client.actor("apidojo/tiktok-scraper").call(run_input={
    "keywords": ["home workout"],
    "sortType": "MOST_LIKED",
    "location": "US",
    "maxItems": 500,
})
videos = list(client.dataset(run.default_dataset_id).iterate_items())
print(len(videos), "videos")
```

`call()` starts the run and waits until it finishes. Each item has `id`, `title`, `views`, `likes`, `comments`, `shares`, `bookmarks`, `uploadedAtFormatted`, `postPage`, a `channel` object and a `song` object.

## How Do You Chain a Comment Scrape Onto Video Results?

**Take the best videos from the first run and pass their `postPage` links to the TikTok Comments Scraper.** This collects the conversation under the videos that matter, instead of every video.

```
top = sorted(videos, key=lambda v: v["views"], reverse=True)[:10]

run = client.actor("apidojo/tiktok-comments-scraper").call(run_input={
    "startUrls": [v["postPage"] for v in top if v["comments"] >= 10],
    "includeReplies": False,
    "maxItems": 5000,
})
comments = list(client.dataset(run.default_dataset_id).iterate_items())
print(len(comments), "comments")
```

The `comments >= 10` check respects the Comments Scraper’s minimum of 10 comments per video ([Apify](https://apify.com/apidojo/tiktok-comments-scraper)). The comment fields are listed in [how to scrape TikTok comments and replies](/blog/tiktok-scraping/scrape-comments/).

## How Do You Clean and Save TikTok Data in Python?

**Load the results into pandas, drop duplicates on `id`, parse the dates, and write CSV or JSON Lines.**

```
import pandas as pd

v = pd.json_normalize(videos).drop_duplicates("id")
v["uploaded"] = pd.to_datetime(v["uploadedAtFormatted"])
v["er"] = (v["likes"] + v["comments"] + v["shares"] + v["bookmarks"]) / v["views"] * 100
v[["id", "postPage", "uploaded", "channel.username", "views", "er", "title"]].to_csv("videos.csv", index=False)

c = pd.json_normalize(comments).drop_duplicates("id")
c.to_json("comments.jsonl", orient="records", lines=True, force_ascii=False)
```

Keep IDs as text in spreadsheets, because long numbers get rounded. The engagement rate formula is explained in [how to calculate TikTok engagement rate](/blog/tiktok-analytics/engagement-rate/).

## How Do You Handle Errors and Limits?

**Check each run’s status, keep inputs above the actors’ minimums, and split large jobs into smaller runs.** Listed below are the 4 rules (Apify).

1.  **Check** `run.status` is `SUCCEEDED` before reading the dataset.
2.  **Give** each query or URL enough content: at least 10 posts on TikTok Scraper, 10 comments on Comments Scraper.
3.  **Don’t** pass single video URLs to TikTok Scraper; it accepts profile, hashtag, search, music and location URLs.
4.  **Split** very large runs into smaller batches.

More on limits and pagination is in [TikTok scraping limits](/blog/tiktok-scraping/limits-pagination/).

## What Does This Script Cost to Run?

**The example above, 500 videos and up to 5,000 comments, costs about $1.65: $0.15 for the videos and $1.50 for the comments.** Both actors charge $0.30 per 1,000 items (Apify, Apify).

## The scrapers behind this

-   [TikTok Scraper Profiles, videos, hashtags, music and locations; 460 posts/sec measured $0.30 / 1K posts](/scrapers/tiktok-scraper/)
-   [TikTok Comments Scraper Comments, likes and replies from video URLs; 100–200 comments/sec $0.30 / 1K comments](/scrapers/tiktok-comments-scraper/)

## Questions people ask

### Is there an official TikTok Python library?

TikTok's official APIs are called over HTTP; there's no official library for collecting public data, and its Research API is limited to approved academics.

### Can you run the script on a schedule?

Yes, with cron or an Apify schedule; see [how to monitor TikTok trends with an API](/blog/tiktok-scraping/monitor-trends/).

### Can you use JavaScript instead?

Yes, the `apify-client` npm package works the same way.

### Where do the results go?

Into each run's dataset on Apify, which you can also download as JSON, CSV or Excel.

## More on scraping TikTok data

-   [How to Scrape TikTok Data in 2026 What TikTok data you can scrape, the 3 ways to collect it, which apidojo actor fits each task, limits, costs and Python code.](/blog/tiktok-scraping/how-to-scrape-tiktok/)
-   [How to Scrape TikTok Comments and Replies Export every comment and reply on any public TikTok video with text, likes, language and commenter profile, plus Python code.](/blog/tiktok-scraping/scrape-comments/)
-   [How to Scrape TikTok Profiles and Their Videos Scrape TikTok profiles by username with apidojo's actors, get every video's stats and the creator's details, and turn them into creator benchmarks.](/blog/tiktok-scraping/scrape-profiles/)
-   [How to Scrape TikTok Followers and Following Lists Export TikTok follower and following lists with profile details, the limits on large and hidden lists, and how to use the data.](/blog/tiktok-scraping/scrape-followers/)
-   [How to Scrape TikTok Hashtag Pages Collect every video on a TikTok hashtag with views, likes and creators, measure the hashtag's daily growth, and find who drives it.](/blog/tiktok-scraping/scrape-hashtags/)
-   [How to Scrape TikTok Search Results Scrape TikTok keyword search results by country and sort order, turn video results into a creator list, and see what it costs.](/blog/tiktok-scraping/scrape-search-results/)
-   [How to Scrape TikTok Sounds and Music Data Scrape the videos using any TikTok sound, read the song fields, measure a sound's growth, and extract audio from your own videos.](/blog/tiktok-scraping/scrape-sounds/)
-   [How to Scrape Location-Tagged TikTok Videos Scrape TikTok videos tagged at a venue or landmark, target results by country, and use location data for local research.](/blog/tiktok-scraping/scrape-locations/)
-   [How to Download TikTok Videos in Bulk Collect TikTok video links in bulk, download the files with Python, keep their details, and follow the rules on rights and reuse.](/blog/tiktok-scraping/bulk-download-videos/)
-   [TikTok Scraping Limits: Pagination and Rate Limits The documented limits of apidojo's TikTok actors, how pagination and maxItems work, and fixes for runs that return too few results.](/blog/tiktok-scraping/limits-pagination/)
-   [Why geotagged TikTok posts arrive without a geotag TikTok Location Scraper returns posts filed under a place, and not one field in the output names that place. Here is how to keep the provenance.](/blog/tiktok/tiktok-location-provenance/)
-   [TikTok date windows that return nothing, and why TikTok Profile Scraper's since and until mean the opposite of what almost everyone assumes. Swap them and the run returns an empty dataset.](/blog/tiktok/tiktok-since-until/)
-   [Why your TikTok user run cost three queries getFollowers and getFollowing are both on by default, and each is its own charge on top of the profile lookup. An unconfigured run bills three times.](/blog/tiktok/tiktok-user-defaults/)

![apidojo](/blog/authors/apidojo.png)

## [Apidojo](/blog/authors/apidojo/)

15+ years of experience in data retrieval.

API Dojo is always ready for you. With 15+ years of experience, data acquisition has never been that easy. Cheapest prices with high availability.

-   🏯 15+ years of experience in data retrieval.
-   💰 Cheapest prices, qualified data.
-   ⚙️ High availability, extreme maintenance.
-   🐉 Hyper communicative, excellent support.

-   [apify.com](https://apify.com/apidojo)
-   [x.com](https://x.com/apidojo_)
-   [github.com](https://github.com/apidojo-io)
