How to Get YouTube Transcripts in Python
Two ways to pull YouTube transcripts in Python: the open-source youtube-transcript-api library, and a hosted REST API. Working code for both, and where the self-hosted approach breaks in production.
00:07:00 · SEP 26, 2026
Quick answer
Install the open-source library
youtube-transcript-api is a well-maintained Python package that fetches YouTube's own caption data directly - no API key, no YouTube Data API quota.
pip install youtube-transcript-apiFetch a transcript with a video ID:
from youtube_transcript_api import YouTubeTranscriptApi
api = YouTubeTranscriptApi()
transcript = api.fetch("dQw4w9WgXcQ", languages=["en"])
for snippet in transcript:
print(snippet.text, snippet.start, snippet.duration)Where this breaks once you deploy it
This works reliably on a laptop. Deployed to a cloud server, it can hit real, well-documented failures - IP blocking, PoTokenRequired, and a 'transcripts disabled' error that isn't always what it looks like. See the full diagnostic checklist for the exact causes and fixes.
Get an API key (if you'd rather not self-host)
Grab a free key from the dashboard - 100 free credits, no card required.
pip install requestsCall the hosted API from Python
No proxy pool, no IP-blocking maintenance - just an HTTP request:
import requests
response = requests.get(
"https://getyoutubetranscript.com/api/v1/transcript",
params={"v": "dQw4w9WgXcQ"},
headers={"Authorization": "Bearer sk_live_..."},
)
result = response.json()
print(result["data"]["transcript"])
print(result["data"]["word_count"])A failed request returns an error object instead of raising a library-specific exception, so the same error handling works across every endpoint.
{ "success": false, "code": "...", "message": "..." }Fetching more than one video
Looping over a list of video IDs works the same way - just watch your plan's requests-per-minute limit. See the rate limit guide for backoff and retry logic.
Both approaches return the same information - the tradeoff is who maintains the infrastructure that keeps working. See full pricing (100 free credits, no card required) or read the API docs for every endpoint.
Python YouTube Transcript FAQ
Which approach should I use?
youtube-transcript-api for a quick local script or prototype. A hosted API once you're deploying to production and don't want to maintain proxy/IP-blocking workarounds yourself.
Does the hosted API require the youtube-transcript-api library?
No - it's a plain REST API. Call it with any HTTP client (requests, httpx, even curl); no Python-specific dependency required.
Can I get timestamps for each line, not just the full text?
The open-source library returns per-snippet start/duration timestamps directly. Our hosted API's transcript endpoint currently returns the full transcript as flat text plus a word count, not per-segment timestamps - if your use case needs segment-level timing specifically from the API, the open-source library is the better fit today.
What happens if a video has no transcript?
Both approaches return a specific error rather than an empty string - see the diagnostic checklist for what each error code means.
Related
- YouTube API Quota Exceeded: Causes and Fixes
- YouTube Transcript API Rate Limit: What It Is and How to Handle 429s
- YouTube Transcript MCP Server: Setup Guide for Claude and Other AI Tools
- YouTube Transcripts in n8n: HTTP Request Workflow Guide
- Migrating from Supadata: A Field Guide
- Migrating from TranscriptAPI.com: A Field Guide
- Build an AI YouTube Video Summarizer with LangChain and Next.js
- GetYouTubeTranscript vs TranscriptAPI
- GetYouTubeTranscript vs youtubetotranscript.com
- GetYouTubeTranscript vs youtube-transcript.io
- GetYouTubeTranscript vs NoteGPT