How to get YouTube video views and likes in Python

Checked on 2026-11-18.

The page of a YouTube video shows rounded numbers such as "1.7M views". From code you can get the exact ones. Here are three ways, and for long lists of videos the official API is the one to use.

1. The official YouTube Data API

videos.list costs 1 quota unit per call, and one call takes several video IDs separated by commas. With 10,000 units a day by default, this is the cheapest way to read numbers for many videos. You need a Google Cloud project and an API key.

Python
import os
import requests

ids = ["jNQXAC9IVRw", "dQw4w9WgXcQ"]
page = requests.get(
    "https://www.googleapis.com/youtube/v3/videos",
    params={
        "part": "snippet,statistics,contentDetails",
        "id": ",".join(ids),
        "key": os.environ["YOUTUBE_API_KEY"],
    },
    timeout=30,
).json()
for item in page["items"]:
    stats = item["statistics"]
    print(
        item["snippet"]["title"],
        int(stats["viewCount"]),
        stats.get("likeCount"),           # missing when the owner hides likes
        stats.get("commentCount"),        # missing when comments are turned off
        item["contentDetails"]["duration"],  # ISO 8601, such as PT15M33S
    )

Three details save time. The counts arrive as text, so convert them with int(). The length is an ISO 8601 duration: PT15M33S means 15 minutes and 33 seconds. And the dislike count is no longer public: Google's reference says it is only returned to the video's owner.

2. yt-dlp, for a few videos on your own computer

Terminal
yt-dlp --print "%(view_count)s %(like_count)s %(duration)s %(title)s" "https://www.youtube.com/watch?v=jNQXAC9IVRw"

It prints the view count, the likes, the length in seconds and the title, and downloads nothing. No key and no quota. From cloud servers YouTube often refuses these requests.

3. An HTTP API, without a Google project

With Pipefetch one request returns the exact counts together with the description, tags, chapters and the channel's subscriber count.

Python
import os
import requests

res = requests.get(
    "https://pipefetch.com/v1/youtube/video",
    params={"video": "https://www.youtube.com/watch?v=jNQXAC9IVRw"},
    headers={"x-api-key": os.environ["PIPEFETCH_API_KEY"]},
    timeout=90,
)
if res.status_code == 404:
    print("Video not found, private or restricted")  # not charged
else:
    res.raise_for_status()
    video = res.json()["data"]
    print(video["title"], video["viewCount"], video["likeCount"], video["commentCount"], video["durationSeconds"])

The numbers are already numbers and the length is in seconds. It is one video per request and 1 credit each, so for thousands of videos the official API is cheaper. The reference lists every field.

Which one should you use?

SituationUse
Numbers for hundreds or thousands of videosThe official API: many IDs per call, 1 unit each call
A quick look at a few videos on your own computeryt-dlp
A server, no Google Cloud project, or you also want tags, chapters and the channel in the same answerAn HTTP API such as Pipefetch

For the latest videos of one channel with their view counts in a single request, see the guide on listing a channel's videos.

Try it with 100 free credits. No card, no Google Cloud project, no OAuth. Get an API key or read the docs.