YouTube comment sections can run into the thousands.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/vsmutok/ytscrape/llms.txt
Use this file to discover all available pages before exploring further.
yt.comments() returns a lazy CommentThread iterator that pages through all of them automatically — you never need to handle a continuation token yourself.
Basic iteration
Pass a video id or any YouTube URL. Usemax_results to cap how many comments you consume:
yt.comments() accepts the same video input formats as yt.video(): a bare 11-character id, a watch?v= URL, a youtu.be/ short link, a /shorts/ URL, or an /embed/ URL.
Collecting replies
By default only top-level comments are collected. Passinclude_replies=True to also expand each thread’s replies. Replies are yielded immediately after the comment they belong to, and they carry is_reply=True:
include_replies=True, max_results counts replies alongside top-level comments.
Sort order
The sort order matters for completeness.| Sort | Constant | What it returns |
|---|---|---|
| Top comments | CommentSort.TOP (default) | Mirrors YouTube’s ranked view — hides some comments flagged as low-relevance or potential spam |
| Newest first | CommentSort.NEWEST | Reverse-chronological — returns every comment |
CommentSort.NEWEST whenever you need to collect all comments, not just the highlighted ones:
sort also accepts the string shorthand: sort="newest" and sort="top" are both valid.
Counting comments
yt.comments() is a lazy iterator, so the total is only known once every page has been consumed. Count as you go, or materialise all comments into a list first:
Full example
The following snippet is drawn from the bundledexamples/07_video_comments.py:
Comment fields
Every comment is a frozen dataclass with the following fields:| Field | Type | Description |
|---|---|---|
comment_id | str | Unique comment id. |
text | str | None | The comment body. |
author | str | None | Display name of the author. |
author_channel_id | str | None | Channel id of the author (when available). |
author_thumbnail | str | None | URL of the author’s avatar image. |
published | str | None | Human-readable published time (e.g. "2 days ago"). |
like_count | int | None | Like count as an integer, or None when abbreviated. |
like_count_text | str | None | Like count as YouTube renders it, preserving abbreviations (e.g. "1.2K", "894"). |
reply_count | int | None | Number of replies (top-level comments only). |
reply_count_text | str | None | Reply count as a raw display string. |
heart | bool | True if the video creator hearted the comment. |
is_reply | bool | True for replies, False for top-level comments. |
like_count is None when YouTube returns an abbreviated string like "1.2K" instead of an exact integer. Use like_count_text whenever you need to display the count exactly as YouTube shows it.Disabled comments
If a video has comments turned off,yt.comments() raises ParseError as soon as the call is made — before you start iterating: