TTechAPI

How to scrape YouTube comments and replies with Python

Comments tell you what an audience thinks, asks and wants next. This guide saves a video's comments and replies to a CSV file in Python, then reads the comments of a whole channel.

Updated 5 December 2026 · TTech Solutions

Python: comments to CSV

GET /comments on the YouTube Channel & Video API returns 20 comments a page and a continuation for the next one. A comment's replyToken, passed as token, opens its replies, which come page by page the same way. The script below saves comments and replies into one CSV file; a reply's parent_id is the id of its comment.

  1. Sign up for free and create an API key in your TTech dashboard.
  2. Send the key in the x-api-key header. Every call goes to https://api.ttechapi.com/v1/youtube plus the endpoint path.
  3. Set the video and the limits at the top, then run the script.
comments_to_csv.py
import csv
import requests

BASE = "https://api.ttechapi.com/v1/youtube"
HEADERS = {"x-api-key": "YOUR_API_KEY"}


def get(path, **params):
    data = requests.get(BASE + path, params=params, headers=HEADERS, timeout=60).json()
    if data.get("error"):  # errors come back as JSON with an error code and a message
        raise RuntimeError(f"{data['error']}: {data.get('msg') or data.get('message')}")
    return data


VIDEO = "arj7oStGLkU"   # a video id or link
MAX_COMMENTS = 100      # top-level comments to save
MAX_REPLIES = 10        # replies to save per comment; 0 skips replies

FIELDS = ["comment_id", "parent_id", "author", "text", "likes", "replies", "date", "pinned", "by_creator"]


def pages(**params):
    """Every page of comments or replies: the first one, then one per continuation token."""
    page = get("/comments", **params)
    while True:
        yield page
        if not page.get("continuation"):
            return
        page = get("/comments", token=page["continuation"])


def row(c, parent_id=""):
    return {
        "comment_id": c["commentId"],
        "parent_id": parent_id,                # empty for a top-level comment
        "author": c["authorText"],
        "text": c["textDisplay"],
        "likes": c["likesCount"],              # as YouTube shows it: "12" or "3K"
        "replies": c.get("replyCount", ""),
        "date": c["publishDate"],              # YYYY-MM-DD
        "pinned": c.get("isPinned", False),
        "by_creator": c.get("authorIsChannelOwner", False),
    }


def replies_of(comment):
    found = []
    if MAX_REPLIES > 0 and comment.get("replyToken"):
        for page in pages(token=comment["replyToken"]):   # a comment's replyToken opens its replies
            found += [row(r, comment["commentId"]) for r in page["data"]]
            if len(found) >= MAX_REPLIES:
                break
    return found[:MAX_REPLIES]


rows, saved = [], 0
for page in pages(id=VIDEO, sort_by="newest"):   # or sort_by="top"
    for c in page["data"]:
        if saved >= MAX_COMMENTS:
            break
        rows.append(row(c))
        rows += replies_of(c)
        saved += 1
    if saved >= MAX_COMMENTS:
        break

with open("comments.csv", "w", newline="", encoding="utf-8") as f:
    writer = csv.DictWriter(f, fieldnames=FIELDS)
    writer.writeheader()
    writer.writerows(rows)
print(saved, "comments and", len(rows) - saved, "replies saved to comments.csv")

Each page of comments or replies is one call and costs 1 credit: one call per 20 comments, plus at least one for each comment that has replies. Set MAX_REPLIES = 0 to save only top-level comments.

comments.csv opened as a table: author, comment text, likes, replies, date and pinned columns for the comments of a TED talk
Real comments of a TED talk in comments.csv (six of its columns). Author names are shortened in this picture only.

The first page also has commentsCount, the total YouTube shows. A video with comments turned off answers an empty data and a msg that says why.

A whole channel

GET /channel/videos lists a channel's videos, 30 a page. Read the comments of each one with the same paging loop:

Python: comments of a channel
import requests

BASE = "https://api.ttechapi.com/v1/youtube"
HEADERS = {"x-api-key": "YOUR_API_KEY"}


def get(path, **params):
    data = requests.get(BASE + path, params=params, headers=HEADERS, timeout=60).json()
    if data.get("error"):  # errors come back as JSON with an error code and a message
        raise RuntimeError(f"{data['error']}: {data.get('msg') or data.get('message')}")
    return data


def comments_of(video_id, limit=100):
    found, page = [], get("/comments", id=video_id, sort_by="top")
    while True:
        found += page["data"]
        if len(found) >= limit or not page.get("continuation"):
            return found[:limit]
        page = get("/comments", token=page["continuation"])


channel = get("/channel/videos", id="@TED", sort_by="newest")   # an @handle, a channel link or a UC id
for video in channel["data"][:10]:   # the 10 newest videos
    for c in comments_of(video["videoId"]):
        print(video["title"], "|", c["authorText"], "|", c["textDisplay"][:80])

Analyze them with an LLM

Give the CSV to ChatGPT or Claude, or connect the TTech MCP server and ask directly. The assistant reads the comments with the youtube_comments tool:

  • "What are the 10 most common questions in these comments?"
  • "Sort the comments into praise, complaints and feature requests, with counts."
  • "Which video ideas do viewers ask for most?"

Run this, then type /mcp in Claude Code and sign in to TTech.

Terminal
claude mcp add --transport http ttech https://mcp.ttechapi.com/mcp

Or install our Claude Code plugin from GitHub. It adds the same server and a YouTube research skill. Then type /mcp and sign in.

Terminal
claude plugin marketplace add ttechapi/claude-plugins
claude plugin install ttech@ttech

To skip the question before each tool call, add "mcp__ttech" to permissions.allow in .claude/settings.json.

Try it with your own account Sign up for free: one account for your API key, your credits and the MCP server.
Sign up for free

FAQ

Why is likes "3K" and not a number?

YouTube shows exact likes only under 1,000. Above that you get YouTube's rounded text.

Can I get every comment of a big video?

Yes, page by page: each page has 20 comments and a continuation token for the next one.

How do I get the replies of a comment?

Pass the comment's replyToken as token to GET /comments. Replies come page by page with their own continuation token, like comments.

Do I need the YouTube API key?

No. A TTech API key is enough, and there is no Google quota.