Scraping YouTube comments in Python: Data API v3, yt-dlp, and InnerTube
You can pull public YouTube comments in Python with Google's Data API v3, with yt-dlp --write-comments, or by calling YouTube's internal /youtubei/v1/next endpoint directly. Each option breaks in a different place once you scale past a few videos: daily API quotas, slow pagination over deep reply threads, or residential IP blocks.
By Subtext ยท Tested December 2026
Read Subtext API docs YouTube Comments API limits Free transcript tool
Three ways to collect YouTube comments in Python
| Method | Page size and fields | Pinned and hearts | Main bottleneck |
|---|---|---|---|
| YouTube Data API v3 | 100 threads; exact ISO dates and integer likes | Not exposed | 10,000 units/day default quota; inline replies incomplete |
yt-dlp --write-comments |
20 threads; relative dates and shorthand likes | Yes (is_pinned, is_favorited) |
Large unmasked responses; HTTP 429 on cloud IPs |
InnerTube /youtubei/v1/next |
20 threads; relative strings ("2 days ago", "1.2K") |
Yes (pinnedText, heartActiveTooltip) |
Unofficial subThreads schema; proxy rotation at scale |
Method 1: Official YouTube Data API v3
For small to medium datasets where exact timestamps and Terms of Service compliance matter, start with Google's commentThreads.list endpoint. Unlike captions.download, reading public comments needs only a standard API key, with no channel-owner OAuth.
import requests
def fetch_threads(
video_id: str, api_key: str, max_pages: int = 5
) -> list[dict]:
url = "https://www.googleapis.com/youtube/v3/commentThreads"
params = {
"part": "snippet,replies",
"videoId": video_id,
"maxResults": 100,
"order": "relevance",
"textFormat": "plainText",
"key": api_key,
}
rows = []
for _ in range(max_pages):
resp = requests.get(url, params=params, timeout=15)
resp.raise_for_status()
data = resp.json()
for item in data.get("items", []):
top = item["snippet"]["topLevelComment"]["snippet"]
rows.append({
"id": item["id"],
"author": top["authorDisplayName"],
"published_at": top["publishedAt"],
"likes": top["likeCount"],
"reply_count": item["snippet"]["totalReplyCount"],
"text": top["textDisplay"],
})
token = data.get("nextPageToken")
if not token:
break
params["pageToken"] = token
return rows
Each call costs 1 quota unit and returns up to 100 top-level threads, so the default 10,000-unit daily pool covers up to 1,000,000 top-level comments if you skip deep replies. Inline replies are typically capped at 5 per thread (Google does not guarantee all replies are included), so whenever totalReplyCount exceeds the inline count you must call comments.list with parentId (1 extra unit per page). See YouTube Comments API quotas and missing fields for the full breakdown.
Method 2: Download comments with yt-dlp
If you want a quick local dump without setting up a Google Cloud project, yt-dlp writes comments into a .info.json file while skipping video download. Always cap max_comments on popular videos so a single command does not spend twenty minutes paging through 100,000 replies:
yt-dlp --skip-download --write-comments --write-info-json \
--extractor-args "youtube:max_comments=500,all,100,20,all" \
"https://www.youtube.com/watch?v=M7lc1UVf-VE"
The five values inside max_comments set max-comments,max-parents,max-replies,max-replies-per-thread,max-depth (pass 1 for max-depth to skip replies completely). The resulting JSON keeps parent IDs, author handles, and creator hearts, which makes exporting to CSV or Excel straightforward in Python.
In server environments (AWS, GCP, Railway, GitHub Actions), yt-dlp runs into the same network limits seen with subtitles: unmasked responses waste proxy bandwidth, and datacenter IPs trigger HTTP 429 or bot-check pages. For the same server tradeoff on subtitles, see yt-dlp transcript download vs a hosted API.
Method 3: Direct InnerTube /youtubei/v1/next with field masks
Both the YouTube web app and yt-dlp fetch comments from POST https://www.youtube.com/youtubei/v1/next?prettyPrint=false. Unlike /youtubei/v1/player (where mobile clients are cleaner for captions), comments work best with the WEB client context and no watch-page HTML download.
Two implementation details trip up older scrapers:
- YouTube no longer puts comment text directly inside
commentRenderer. Each thread inonResponseReceivedEndpointsholds acommentKey(pluspinnedTextand reply continuation tokens undercommentRepliesRendererandsubThreads), while the actual text, author, and like counts arrive inframeworkUpdates.entityBatchUpdate.mutationsundercommentEntityPayload. - In live tests on
M7lc1UVf-VE(December 2026), an unmasked initial/nextcall transferred 73.6 KB gzipped (688 KB decoded), and a 20-comment page transferred 32.4 KB gzipped (254 KB decoded). Passing a$fieldsquery mask for the engagement panel andcommentEntityPayloadfields cut the initial call to 446 bytes (165x smaller) and each 20-comment page to 4.1 KB (~360 ms).
Because InnerTube is an undocumented private API, keep a parser test suite against saved JSON fixtures and fall back cleanly when Google renames a field. At volume from cloud hosts, expect to rotate residential proxies and pin hl=en and gl=US in context.client so shorthand like counts (1.2K) stay consistent.
Pairing scraped comments with video transcripts
Viewer comments reference moments in the video ("3:14 fixed my build", "the claim at 12:40 is wrong"), so analyzing comments without the spoken transcript misses half the context. Subtext currently provides public YouTube transcripts via browser, REST API, and MCP (it reads captions only, not comments). Fetch the timestamped transcript in one request to join against your comment timestamps:
export SUBTEXT_API_KEY=stx_...
curl -sS -H "Authorization: Bearer $SUBTEXT_API_KEY" \
"https://subtextapi.com/api/v1/transcript?video=M7lc1UVf-VE&format=json"
If you run research workflows inside Claude Code or Cursor, connect the Subtext MCP server instead of writing shell glue for transcripts.
When to pick each approach
Use YouTube Data API v3 when you need exact timestamps, integer like counts, or official ToS compliance within 10,000 units per day. Use yt-dlp --write-comments for one-off local research on a personal machine. Build a masked InnerTube client only when you need pinned flags, creator hearts, and low proxy bandwidth at scale and are ready to maintain the parser when YouTube updates subThreads.
Related guides: YouTube Comments API vs Data API v3, YouTube comment sentiment analysis with Python and LLMs, how to copy YouTube comments, YouTube Captions API vs Data API v3, fixing Python YouTube IP blocks, and troubleshooting YouTube comments not showing.