youtube-transcript-api
Fetch transcripts and auto-generated subtitles for any YouTube video in Python
Repository Health
Technical Analysis
youtube-transcript-api retrieves the transcript or subtitle track for a given YouTube video ID directly, without needing a headless browser or an official YouTube Data API key. It works for both manually-created and automatically-generated (ASR) captions, supports listing all available transcript languages for a video, and can translate a transcript into another language using YouTube’s built-in translation feature.
The package ships both a Python API (YouTubeTranscriptApi) and a CLI (youtube_transcript_api) for one-off lookups, plus pluggable output formatters (plain text, JSON, SRT, WebVTT) for converting the raw transcript data into common subtitle formats. It’s widely used in content-summarization tools, transcript-search products, and LLM data pipelines that need YouTube video text without downloading and transcribing the video itself.
What You Get
- A
YouTubeTranscriptApi.fetch()/list()API to retrieve or enumerate a video’s available transcript tracks by video ID - Support for both human-created captions and YouTube’s automatically-generated (ASR) subtitles
- Built-in transcript translation into any language YouTube offers translation for, via the same API
- A CLI (
youtube_transcript_api) for fetching transcripts from the command line without writing Python - Pluggable formatters (
TextFormatter,JSONFormatter,SRTFormatter,WebVTTFormatter) to convert raw transcript data into common subtitle/text formats - Proxy support for routing requests through HTTP/SOCKS proxies or third-party proxy services to avoid IP-based rate limiting
Common Use Cases
- Feeding YouTube video transcripts into an LLM pipeline for summarization or question-answering over video content
- Building a searchable transcript index across a channel or playlist’s videos
- Extracting subtitles in SRT/WebVTT format for downstream video-editing or accessibility workflows
- Translating a video’s transcript into a different language programmatically for localization
- Quickly checking, from the command line, what transcript languages are available for a given YouTube video
Under The Hood
Architecture - The core lookup logic lives in _transcripts.py (~490 lines), which handles parsing YouTube’s internal caption-track metadata for a given video ID, selecting the requested language/track, and fetching+parsing the XML-based transcript payload; _api.py (~130 lines) exposes the public YouTubeTranscriptApi class as a thin, stable facade over that internal machinery, while formatters.py converts the resulting transcript objects into text/JSON/SRT/WebVTT, and _cli.py/__main__.py wire the same API into a command-line entry point. Tech Stack - A dependency-light Python package (requests-based HTTP calls, defusedxml for safe XML parsing of caption data) packaged with Poetry; proxies.py adds optional proxy-provider integrations for users hitting YouTube’s rate limits at scale. Code Quality - The youtube_transcript_api/test directory includes dedicated test modules for the API surface, CLI, formatters, and proxy handling, giving reasonable coverage of the package’s main entry points; the project is typed (ships a py.typed marker) though development pace has slowed (low recent commit activity) even as the underlying YouTube page format it scrapes continues to change. API Design - The public surface is deliberately small — one main class with fetch/list methods and a handful of formatter classes — making it easy to get a transcript in a few lines of code, though because it depends on scraping YouTube’s undocumented internal caption delivery format rather than an official stable API, breaking changes on YouTube’s side occasionally require library updates.
Used by 6 apps in this directory
Agno
Devops · AI Development · Automation
Build, run, and manage agent platforms with a full production stack — SDK, runtime, and control plane included.
auto-news
AI Assistants · Productivity
An AI-powered personal news aggregator that filters multi-source feeds through LLMs and delivers curated, noise-free summaries to your Notion workspace.
AutoGPT
Automation · Productivity · AI Assistants
Build, deploy, and run autonomous AI agents that automate complex multi-step workflows using a visual block-based graph editor.
Langflow
AI Agents · AI Development
Build, test, and deploy AI agents and RAG workflows visually with native API and MCP server export.
Open WebUI
AI Assistants · AI Agents
The extensible, privacy-first AI platform that runs Ollama, OpenAI, and any LLM backend behind a polished, feature-packed web interface.
SurfSense
Search · AI Assistants
The open-source, unlimited NotebookLM alternative with real-time collaboration, a desktop app, and no vendor lock-in.