How to get YouTube comments in Python
Checked on 2026-11-18.
There are four practical ways to read the comments of a YouTube video from Python. Which one fits depends on whether you need every comment or the top ones, and on whether you want to set up a Google Cloud project.
1. The official YouTube Data API
For comments the official API is a good route. commentThreads.list costs 1 quota unit per call and returns up to 100 comment threads, so the default 10,000 units a day go a long way. You need a Google Cloud project and an API key; reading public comments needs no OAuth.
import os
import requests
params = {
"part": "snippet",
"videoId": "jNQXAC9IVRw",
"maxResults": 100, # 1 to 100
"order": "relevance", # or "time", the default
"textFormat": "plainText",
"key": os.environ["YOUTUBE_API_KEY"],
}
while True:
page = requests.get("https://www.googleapis.com/youtube/v3/commentThreads", params=params, timeout=30).json()
for item in page.get("items", []):
comment = item["snippet"]["topLevelComment"]["snippet"]
print(comment["authorDisplayName"], comment["likeCount"], comment["textDisplay"])
if "nextPageToken" not in page:
break
params["pageToken"] = page["nextPageToken"]A video with comments turned off answers 403 with the reason commentsDisabled. Follow nextPageToken until it is gone to read every thread.
2. yt-dlp, into a JSON file
yt-dlp can save a video's comments without downloading the video. They land in the comments list of the .info.json file it writes.
yt-dlp --skip-download --write-comments --extractor-args "youtube:max_comments=100;comment_sort=top" "https://www.youtube.com/watch?v=jNQXAC9IVRw"comment_sort is top or new, and without max_comments it fetches all of them, which takes a long time on a popular video. No API key is needed. From cloud servers YouTube often refuses these requests.
3. The youtube-comment-downloader library
A small library that reads comments without the official API and without a key.
# pip install youtube-comment-downloader
from itertools import islice
from youtube_comment_downloader import *
downloader = YoutubeCommentDownloader()
comments = downloader.get_comments_from_url("https://www.youtube.com/watch?v=jNQXAC9IVRw", sort_by=SORT_BY_POPULAR)
for comment in islice(comments, 10):
print(comment)Like every tool that reads YouTube's pages directly, it depends on an interface YouTube does not document, so it can stop working until it is updated, and it meets the same blocks on servers.
4. An HTTP API, without a Google project
With Pipefetch the top or the newest comments of a video are one HTTPS request with one key, from any server.
import os
import requests
res = requests.get(
"https://pipefetch.com/v1/youtube/comments",
params={"video": "jNQXAC9IVRw", "limit": 100, "sort": "top"}, # or "newest"
headers={"x-api-key": os.environ["PIPEFETCH_API_KEY"]},
timeout=90,
)
if res.status_code == 404:
print("No comments, or comments are turned off") # not charged
else:
res.raise_for_status()
data = res.json()["data"]
print(data["totalComments"], "comments in total")
for comment in data["comments"]:
print(comment["author"]["name"], comment["likeCount"], comment["text"])One limit to know: it returns up to 100 comments per video, the top ones or the newest ones, and no further pages. It costs 1 credit per started 20 comments, so 100 comments are 5 credits. The reference lists every field, including reply counts, pinned and creator-hearted flags.
Which one should you use?
| You need | Use |
|---|---|
| Every comment of a video, or replies | The official API |
| A JSON file on your own computer, no key | yt-dlp |
| The top or newest comments of many videos, from a server, without a Google Cloud project | An HTTP API such as Pipefetch |
Comments are personal data
A comment comes with its author's public name and channel. Under laws such as the GDPR that is personal data, whichever route you used to fetch it. Keep only what your purpose needs, and do not publish lists of commenters.
Try it with 100 free credits. No card, no Google Cloud project, no OAuth. Get an API key or read the docs.
APIs used in this guide
-
1 credit
YouTube Video API
Exact views, likes and comment count, description, tags, chapters and channel for one video.
GET /v1/youtube/video -
1 credit / 20
YouTube Comments API
Top or newest comments of a video with likes, reply counts, pinned and hearted flags.
GET /v1/youtube/comments
More guides
- How to get a YouTube transcript in Python
- How to get a YouTube transcript in Node.js
- YouTube API quota exceeded: what the error means and how to fix it
- How to find a YouTube channel ID from a handle or URL
- How to download YouTube subtitles as SRT or VTT
- youtube-transcript-api RequestBlocked or IpBlocked: why it happens and how to fix it
- How to search YouTube from Python
- How to list a YouTube channel's videos in Python
- How to summarize a YouTube video with an LLM in Python