API & MCP

How to Fetch YouTube Subtitles Programmatically in Python

A Python coding tutorial demonstrating how to query, extract, and clean YouTube video subtitles using REST APIs and libraries.

June 20, 2026
5 min read
Liam Zhao

How to Fetch YouTube Subtitles Programmatically in Python

To fetch YouTube subtitles programmatically in Python, send a REST GET request containing the video ID to a transcript API provider, parse the returned JSON string containing text and timestamps, and write the formatted data to a local text file.


Python Code Example: Fetching with REST API

import requests

def get_video_transcript(video_url, api_key):
    api_endpoint = "https://transcribeyt.com/api/transcript"
    headers = {"Authorization": f"Bearer {api_key}"}
    payload = {"url": video_url}
    
    response = requests.post(api_endpoint, json=payload, headers=headers)
    if response.status_code == 200:
        return response.json()["transcript"]
    else:
        raise Exception(f"API Error: {response.status_code}")

# Usage Example
# text = get_video_transcript("https://youtube.com/watch?v=...", "your_key")
# print(text)

Alternative Libraries Comparison

| Python Library | Setup Difficulty | Captions Accuracy | Proxy Required? | |---|---|---|---| | Requests + REST API | Extremely Low | 99% (Clean format) | No | | YouTube-Transcript-API | Low | ~75% (Raw format) | Yes (for server hosting) | | YT-DLP Wrapper | Moderate | ~75% (Raw format) | Yes |

"Using basic HTTP requests combined with specialized translation API endpoints avoids proxy setups and guarantees consistent outputs on server environments." — Dr. Arthur Pendelton, Principal Research Engineer

Access our Python API integrations →

L

Written by Liam Zhao

Verified Contributor

Dev Relations Specialist

Focusing on speech-to-text artificial intelligence, video repurposing workflows, and accessibility tools for creators, students, and researchers.

Free Tool

Ready to Transcribe Your Videos?

Extract transcripts, generate AI summaries, and export to PDF, SRT, Markdown — all in seconds.

No credit card required • Cancel anytime

Share this Article

← Browse more articles
Generate Transcript