Back to blogIntegrations

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 youtube-transcript-api for a quick local script, or call a hosted REST API if you don't want to deal with IP blocking and PoToken issues once you deploy. Both are covered below with working code.
01

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-api

Fetch 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)
02

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.

03

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 requests
04

Call 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": "..." }
05

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

Q01

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.

Q02

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.

Q03

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.

Q04

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