DEV Community

LogicBase Systems
LogicBase Systems

Posted on

How to get ALL YouTube comments and replies in Python (and why you only get some)

Disclosure: the last section uses an Apify Actor I made, so I'm biased. Apify links here are referral links. Everything before that is free and needs no API key.

You want every comment on a YouTube video, replies included, and you keep getting only part of them. There are three common reasons:

  1. With the official API, commentThreads.list returns only some replies per thread.
  2. With yt-dlp, the default "top comments" order can stop early on big videos, and with warnings switched off you won't notice.
  3. Replies can point at other replies, so code that groups replies by their parent drops some of them.

Here is what the official docs say, and a free Python script that got all of them in my tests on 24 November 2026.

The official API: replies need a second call

From Google's commentThreads reference: a thread's replies.comments[] "contains a limited number of replies". Unless its length equals snippet.totalReplyCount, it is only a subset. To get all replies you have to call comments.list with parentId set to the top-level comment ID.

So the full official recipe is:

  • page through commentThreads.list?videoId=...&part=snippet,replies&maxResults=100 (100 is the maximum per page),
  • for every thread where totalReplyCount is larger than the replies you got, page through comments.list?parentId=...&maxResults=100.

Both methods cost 1 quota unit per call, and every page is a call. Spread over the default 10,000 units a day, that is fine for a few videos. On a video with thousands of threads that have replies, it adds up fast. (I covered the quota itself in YouTube Data API quotaExceeded (403): why your quota runs out and 3 ways to fix it.)

I had no API key on the test machine today, so the official part above comes from Google's docs, not from my own runs. Everything below I ran myself.

The free route: yt-dlp, no key

yt-dlp can read the comments YouTube shows on the watch page, replies included. I used yt-dlp 2026.11.23 on Python 3.13.

pip install -U yt-dlp
Enter fullscreen mode Exit fullscreen mode

The quickest way is the command line. It writes VIDEO_ID.info.json with a comments list inside:

yt-dlp --skip-download --write-comments \
  --extractor-args "youtube:comment_sort=new" \
  -o "%(id)s" "https://www.youtube.com/watch?v=cdblJqEUDNo"
Enter fullscreen mode Exit fullscreen mode

The log line Downloading ~144 comments is the count YouTube shows. At the end you get Extracted 144 comments.

A Python script that keeps threads together

import csv
import sys
from collections import defaultdict
from yt_dlp import YoutubeDL

def get_comments(url, sort="new", limit=None):
    youtube_args = {"comment_sort": [sort]}
    if limit:
        # total comments, top-level threads, total replies, replies per thread
        youtube_args["max_comments"] = [str(limit), "all", "all", "all"]
    opts = {
        "skip_download": True,
        "getcomments": True,
        "quiet": True,
        "extractor_args": {"youtube": youtube_args},
    }
    with YoutubeDL(opts) as ydl:
        info = ydl.extract_info(url, download=False)
    return info, info.get("comments") or []

url = sys.argv[1] if len(sys.argv) > 1 else "https://www.youtube.com/watch?v=cdblJqEUDNo"
limit = int(sys.argv[2]) if len(sys.argv) > 2 else None
info, comments = get_comments(url, limit=limit)

top_level = [c for c in comments if c["parent"] == "root"]
# A reply's parent can be another reply, so group by thread instead:
# reply IDs look like "<top-level ID>.<reply ID>".
replies = defaultdict(list)
for c in comments:
    if c["parent"] != "root":
        replies[c["id"].split(".")[0]].append(c)

print(info["title"])
print(f"{len(comments)} comments: {len(top_level)} top-level + "
      f"{len(comments) - len(top_level)} replies")

with open("comments.csv", "w", newline="", encoding="utf-8") as f:
    w = csv.writer(f)
    w.writerow(["thread_id", "comment_id", "parent_id", "author",
                "likes", "time", "text"])
    for t in top_level:
        for c in [t] + replies[t["id"]]:
            w.writerow([t["id"], c["id"], c["parent"], c["author"],
                        c.get("like_count"), c.get("_time_text"), c["text"]])

if top_level:
    busiest = max(top_level, key=lambda t: len(replies[t["id"]]))
    print(f"Busiest thread: {len(replies[busiest['id']])} replies to "
          f"{busiest['text'][:60]!r}")
Enter fullscreen mode Exit fullscreen mode

Run it with a video URL, plus an optional cap on the total number of comments:

python all_comments.py "https://www.youtube.com/watch?v=cdblJqEUDNo"
python all_comments.py "https://www.youtube.com/watch?v=aircAruvnKk" 300
Enter fullscreen mode Exit fullscreen mode

The first one printed 144 comments: 130 top-level + 14 replies in about 3 seconds, matching the ~144 YouTube showed. The CSV has one row per comment, with each top-level comment followed by its replies.

yt-dlp also prints a warning about a missing JavaScript runtime. That affects video formats; comments came through without one in all my runs.

Gotcha 1: "top" order can stop early

yt-dlp's default order is YouTube's "Top comments". On 3Blue1Brown's neural network video (YouTube showed ~9,617 comments), the top order stopped after page 59 with:

WARNING: [youtube] Incomplete data received. Giving up after 3 retries
[youtube] Extracted 2549 comments
Enter fullscreen mode Exit fullscreen mode

That is about a quarter of the comments. If you also pass no_warnings: True, the only sign is the smaller count. Switching to comment_sort=new on the same video returned 9,558 comments (7,503 top-level + 2,055 replies) in about 2 minutes. On the small video, the top order returned 142 comments and the newest order 144.

That is why the script defaults to "new" and keeps warnings on. If you need the most-liked comments, fetch with "new" and sort by like_count yourself.

Gotcha 2: replies to replies

On the same big video, a 300-comment test in top order returned 295 replies, and 87 of them had a parent that was another reply, not the top-level comment. In the full newest-order download, 567 of the 2,055 replies pointed at another reply. Code that does replies[c["parent"]] and then loops over top-level comments silently loses those. All reply IDs I got had the form <top-level ID>.<reply ID>, so the script groups on the part before the dot and keeps parent_id in the CSV if you want to rebuild the nesting.

Gotcha 3: one huge thread can eat your cap

max_comments takes four numbers: total comments, top-level threads, total replies, replies per thread (all means no limit). In top order with a cap of 300, I got 5 top-level comments and 295 replies, 170 of them in one thread. With 300,all,all,5 instead, the same 300 comments covered 88 threads, at most 5 replies each. Set the fourth number when you want a broad sample rather than one long argument.

Things to know

  • This reads what YouTube shows on public pages. It can't see private or members-only videos, or comments held for review.
  • YouTube often rate-limits or blocks this kind of request when it comes from a cloud server. My tests ran from one machine at small volume.
  • Respect YouTube's terms and the commenters' privacy, especially if you republish comment text.

When you need many videos: a hosted option

For a few videos, the script above is all you need. If you want comments for hundreds of videos on a schedule, without running yt-dlp yourself, my YouTube Data Scraper on Apify returns video stats plus each video's top or newest comments in one run.

To be clear about what it does and doesn't do: it returns top-level comments only. It doesn't return reply text. Each comment row has a replyCount, plus author, likes, and pinned / "hearted by the creator" flags. A good use is finding the threads worth expanding:

import os
from apify_client import ApifyClient

client = ApifyClient(os.environ["APIFY_TOKEN"])
run = client.actor("logicbase_systems/youtube-data-scraper").call(run_input={
    "videoUrls": ["aircAruvnKk", "cdblJqEUDNo"],
    "includeComments": True,
    "maxComments": 10,
    "commentSort": "top",
})

rows = list(client.dataset(run.default_dataset_id).iterate_items())
videos = {r["id"]: r for r in rows if r.get("type") == "video"}
comments = [r for r in rows if r.get("type") == "comment"]
print(f"{len(videos)} videos, {len(comments)} top-level comments")

# Threads with the most replies: these are the ones worth expanding
for c in sorted(comments, key=lambda c: c["replyCount"], reverse=True)[:5]:
    print(f'{c["replyCount"]:>4} replies  {c["videoId"]}  {c["text"][:50]!r}')
Enter fullscreen mode Exit fullscreen mode
pip install -U apify-client
export APIFY_TOKEN="..."   # from Settings → API & Integrations in a free Apify account
Enter fullscreen mode Exit fullscreen mode

On 24 November 2026 this returned 2 videos and 20 comments; the busiest thread had 175 replies. The run took about 21 seconds inside Apify. Then run the yt-dlp script above on the videos whose threads you want in full.

Pricing is $0.002 per video and $0.0015 per comment returned, plus a $0.00005 start fee per run, so that test costs about $0.034. You need a free Apify account and its API token.

Summary

  1. Official API: commentThreads.list gives only some replies; call comments.list?parentId=... for the rest, at 1 unit per page.
  2. No key: yt-dlp with comment_sort=new returned all, or almost all, comments in my tests. "Top" stopped at about a quarter on a big video.
  3. Group replies by the thread ID (the part before the dot), not by parent.
  4. For many videos, a hosted scraper can give you the top-level comments and reply counts; expand only the threads you need.

For video stats, search results and channel listings with the same Actor, see my earlier walkthrough: How to scrape YouTube video stats, search results and comments without an API key.

Top comments (0)