youtube-transcript-api is the simplest way to get a YouTube transcript in Python, and it's actively maintained. It has one problem it can't fix in code: YouTube blocks requests from cloud servers. Its README says so under "Working around IP bans": YouTube blocks "most IPs that are known to belong to cloud providers (like AWS, Google Cloud Platform, Azure, etc.)", and it recommends paying for rotating residential proxies.
So the script that works on your laptop raises RequestBlocked in production (#397), or a 429 (#467), and some users report failures even through rotating residential proxies (#552). Version 1.2.0 also removed get_transcript and list_transcripts, so older code breaks on upgrade.
This guide gets the same transcripts with SocialTap, from any server, along with the video's details, a channel's videos and their comments.
The code that breaks in production
from youtube_transcript_api import YouTubeTranscriptApi
ytt_api = YouTubeTranscriptApi()
transcript = ytt_api.fetch("dQw4w9WgXcQ")
for snippet in transcript:
print(snippet.start, snippet.text)From a cloud IP, fetch raises RequestBlocked or IpBlocked, and the fix the README offers is a proxy configuration you pay for and maintain.
The same transcript with one API key
SocialTap reads YouTube for you, through its own proxies, and returns the transcript in one schema. Install the SDK:
pip install socialtapGet a key on the signup page and set it as SOCIALTAP_API_KEY. Every account starts with 100 free credits. Then, from your server or anywhere else:
from socialtap import SocialTap, APIError, NotFoundError, PrivateOrUnavailableError, NoTranscriptError
client = SocialTap() # api_key defaults to os.environ["SOCIALTAP_API_KEY"]
try:
res = client.youtube.transcript.get(url="dQw4w9WgXcQ")
print(res.data)
print(res.credits.charged, res.meta.request_id)
except NotFoundError as err:
# The item does not exist or was deleted.
print(err.code, err.remediation)
except PrivateOrUnavailableError as err:
# The item exists but isn't public: it is private, age- or region-restricted, or needs a login.
print(err.code, err.remediation)
except NoTranscriptError as err:
# The video or audio exists but has no transcript: no captions, and speech-to-text found no speech or didn't run (the media is too long without transcribe_audio=true, or transcribe_audio=false).
print(err.code, err.remediation)
except APIError as err:
# Retryable errors reach you only after the SDK's own retries. Failed requests cost no credits.
print(err.code, err.status, err.retryable, err.remediation, err.request_id)Send a watch link, a youtu.be link, a Shorts link or the 11-character ID. The answer has:
segments, each withstart_ms,end_msand its text, ready to write as SRT or VTT.text, the whole transcript in one string, for a summary or a search index.is_auto_generated, which says whether you got the creator's captions or YouTube's automatic ones (the creator's win).available_languages, the caption tracks you can ask for withlang.
A video with no captions is transcribed from its audio, at the speech-to-text price: short videos by default, any length with transcribe_audio=True. A video with nothing to transcribe raises NoTranscriptError, which the program above catches.
From youtube-transcript-api to SocialTap
| youtube-transcript-api | SocialTap | Endpoint |
|---|---|---|
YouTubeTranscriptApi().fetch(video_id) | client.youtube.transcript.get() | YouTube Transcript API |
YouTubeTranscriptApi().list(video_id) | available_languages in the same answer | YouTube Transcript API |
fetch(video_id, languages=["de"]) | lang="de" | YouTube Transcript API |
And what the library doesn't read: a video's views, likes, chapters and description with client.youtube.post.get(), a channel's videos with client.youtube.posts.iterate() and their comments with client.youtube.comments.iterate().
What it costs
You pay per successful request:
- Transcripts from captions: $0.75–$1.97 per 1,000 transcripts. Speech-to-text, for videos without captions, costs more: the YouTube Transcript API page has its price.
- Videos of a channel: $0.02–$0.04 per 1,000 posts.
Failed requests, including a video with no transcript, cost nothing, and so do cache hits. There are no proxies to rent and nothing to maintain.
Frequently asked questions
Why does youtube-transcript-api work locally but not on my server?
YouTube blocks most IP addresses that belong to cloud providers, as the library's README explains. Your laptop's home IP passes, and AWS, Google Cloud or Azure IPs get RequestBlocked or IpBlocked.
What happened to get_transcript?
Version 1.2.0 removed get_transcript, get_transcripts and list_transcripts. The library now uses an instance: YouTubeTranscriptApi().fetch(video_id) and .list(video_id).
Can I get transcripts in other languages?
Yes. available_languages lists the caption tracks, and lang picks one, such as de or pt-BR.
Do Shorts and live streams work?
Yes. Shorts and live replays have transcripts like any video. A scheduled stream, or one whose recording isn't available, raises NoTranscriptError.
Is the official YouTube Data API an option?
Not for this. The YouTube Data API downloads captions only for videos your account can edit, so it can't read other channels' transcripts. The YouTube API page compares the two.