How to get a YouTube transcript in Python
Checked on 2026-11-18.
There are three practical ways to get the transcript of a YouTube video from Python. Two are free and fine on your own computer. The third is for code that runs on a server, where the free ones tend to get blocked.
1. The youtube-transcript-api library
The quickest start. It is free, needs no API key and reads the same captions YouTube shows in its player.
# pip install youtube-transcript-api
from youtube_transcript_api import YouTubeTranscriptApi
transcript = YouTubeTranscriptApi().fetch("jNQXAC9IVRw")
for snippet in transcript:
print(snippet.start, snippet.text)Where it breaks: on servers. The library's own README says YouTube blocks most IP addresses that belong to cloud providers, so a script that works on your laptop often fails on AWS, Google Cloud, Azure or a VPS with a RequestBlocked or IpBlocked error. The fix the README describes is to send requests through rotating residential proxies, which you then have to buy and manage. The call above matches the library's current interface; older tutorials use a get_transcript call that no longer exists.
2. yt-dlp, when you want subtitle files
yt-dlp is a command-line tool that can save a video's captions as a file without downloading the video.
yt-dlp --skip-download --write-subs --write-auto-subs --sub-langs en --sub-format vtt "https://www.youtube.com/watch?v=jNQXAC9IVRw"You get a .vtt file that you parse yourself. It is a good fit for one-off jobs on your own machine. From a server it meets the same blocks as the library.
3. An HTTP API, for code that runs on a server
With Pipefetch the transcript is one HTTPS request, so it works the same from a laptop, a cloud function or a container, and there are no proxies to run.
import os
import requests
res = requests.get(
"https://pipefetch.com/v1/youtube/transcript",
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("No captions for this video") # not charged
else:
res.raise_for_status()
data = res.json()["data"]
print(data["text"]) # the whole transcript
for segment in data["segments"]: # timed pieces
print(segment["start"], segment["text"])Add lang to choose a caption language, or format set to srt or vtt to get a ready subtitle file in the text field. A request costs 1 credit, a video without captions costs nothing, and a new account has 100 free credits. The reference lists every parameter.
Which one should you use?
| Situation | Use |
|---|---|
| A script on your own computer, a few videos | youtube-transcript-api |
| You want .vtt or .srt files on disk | yt-dlp |
| A web app, a scheduled job or anything in the cloud | An HTTP API such as Pipefetch, or the library with paid proxies |
Why not the official YouTube Data API?
Its captions.download method only works for videos you own or manage, and it needs OAuth. It cannot return the captions of someone else's public video, which is why every method above reads the public captions instead.
When there is no transcript at all
All three methods return the captions YouTube already has, uploaded or auto-generated. If a video has neither, there is nothing to fetch, and you would need speech recognition on the audio.
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 Transcript API
The transcript of any public video with captions, as plain text, timestamped segments, SRT or WebVTT.
GET /v1/youtube/transcript -
1 credit
YouTube Video API
Exact views, likes and comment count, description, tags, chapters and channel for one video.
GET /v1/youtube/video