A REST API wrapper for the python youtube-transcript-api application
1.7K
A lightweight, production-ready REST API service that extracts and formats YouTube video transcripts (subtitles/captions). Built with FastAPI and powered by the excellent youtube-transcript-api Python library.
This Docker container provides a simple REST API interface to fetch YouTube video transcripts without needing the YouTube Data API or authentication. It's perfect for:
docker pull oldgrandpavanu/youtubetranscriptapi:latest
docker run -d -p 8000:8000 --name youtube-transcript-api oldgrandpavanu/youtubetranscriptapi:latest
Access the API at http://localhost:8000 and documentation at http://localhost:8000/docs
docker run -d -p 8000:8000 -e API_KEY=your_secret_key_here --name youtube-transcript-api oldgrandpavanu/youtubetranscriptapi:latest
Create a compose.yaml file:
services:
api:
image: oldgrandpavanu/youtubetranscriptapi:latest
ports:
- "8000:8000"
environment:
- API_KEY=${API_KEY:-} # Optional: set via environment variable
restart: unless-stopped
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000/"]
interval: 30s
timeout: 10s
retries: 3
Start the service:
# Without API key
docker compose up -d
# With API key protection
API_KEY=your_secret_key_here docker compose up -d
GET / - Welcome message and API informationGET /transcript - Fetch video transcript in various formatsGET /transcripts - List all available transcripts for a videoGET /docs - Interactive Swagger UI documentationGET /redoc - ReDoc API documentationFetch a transcript in JSON format (default):
curl "http://localhost:8000/transcript?video_id=dQw4w9WgXcQ&language=en"
Fetch as plain text:
curl "http://localhost:8000/transcript?video_id=dQw4w9WgXcQ&language=en&format=text"
Fetch as SRT subtitles:
curl "http://localhost:8000/transcript?video_id=dQw4w9WgXcQ&language=en&format=srt"
Fetch as WebVTT:
curl "http://localhost:8000/transcript?video_id=dQw4w9WgXcQ&language=en&format=webvtt"
Parameters:
video_id (required): YouTube video IDlanguage (optional, default: "en"): Language code (e.g., "en", "es", "fr", "de")format (optional, default: "json"): Output format - json, text, webvtt, or srtDiscover all available transcript languages for a video:
curl "http://localhost:8000/transcripts?video_id=dQw4w9WgXcQ"
Response Example:
{
"video_id": "dQw4w9WgXcQ",
"available_transcripts": [
{
"language": "English",
"language_code": "en",
"is_generated": false,
"is_translatable": true
},
{
"language": "Spanish",
"language_code": "es",
"is_generated": true,
"is_translatable": true
}
]
}
When the API_KEY environment variable is set, include the key in your requests:
curl -H "X-API-Key: your_secret_key_here" \
"http://localhost:8000/transcript?video_id=dQw4w9WgXcQ&language=en"
| Variable | Required | Default | Description |
|---|---|---|---|
API_KEY | No | None | When set, requires X-API-Key header for all protected endpoints |
API_KEY_FILE | No | None | Path to file containing API key (recommended for production). Mutually exclusive with API_KEY |
For production environments, use Docker secrets instead of environment variables for enhanced security.
# Create the secret
echo "your_production_api_key" | docker secret create api_key -
# Deploy as a service
docker service create \
--name youtube-transcript-api \
--secret api_key \
--env API_KEY_FILE=/run/secrets/api_key \
--publish 8000:8000 \
--replicas 3 \
oldgrandpavanu/youtubetranscriptapi:latest
# Or using docker stack with compose file
docker stack deploy -c compose.yaml youtube-transcript-api
Create a compose.yaml:
services:
api:
image: oldgrandpavanu/youtubetranscriptapi:latest
ports:
- "8000:8000"
environment:
- API_KEY_FILE=/run/secrets/api_key
secrets:
- api_key
restart: unless-stopped
secrets:
api_key:
file: ./secrets/api_key.txt # For local dev
# external: true # For production swarm
Then create the secret file and start:
mkdir -p secrets
echo "your_secret_key" > secrets/api_key.txt
chmod 600 secrets/api_key.txt
docker compose up -d
For Kubernetes deployments:
# Create the secret
kubectl create secret generic youtube-api-key \
--from-literal=api-key=your_secret_key_here
# Reference in deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: youtube-transcript-api
spec:
template:
spec:
containers:
- name: api
image: oldgrandpavanu/youtubetranscriptapi:latest
env:
- name: API_KEY
valueFrom:
secretKeyRef:
name: youtube-api-key
key: api-key
Using the _FILE suffix pattern with Docker secrets provides:
docker inspect: Secrets are not visible in container metadataThe API provides meaningful HTTP status codes and error messages:
| Status Code | Scenario |
|---|---|
| 200 | Success |
| 401 | Invalid or missing API key (when protection enabled) |
| 403 | Age-restricted content or IP blocked by YouTube |
| 404 | Video unavailable, transcript not found, or transcripts disabled |
| 429 | Request blocked by YouTube (rate limiting) |
| 500 | Internal server error |
For development, mount the application directory:
docker run -p 8000:8000 -v $(pwd):/app oldgrandpavanu/youtubetranscriptapi:latest
The application follows a clean, single-file architecture (main.py) with:
Extract transcripts for sentiment analysis, keyword extraction, or topic modeling.
Convert video content to readable text or downloadable subtitle files.
Create study materials from educational videos or generate summaries.
Analyze large collections of video content for academic research.
Integrate into workflows, automation tools, or content management systems.
Once the container is running, access the interactive documentation:
GitHub Repository: https://github.com/coryrolstad/YoutubeTranscriptApi
MIT License - Free for personal and commercial use.
This project is a REST API wrapper around the excellent youtube-transcript-api Python package maintained by Jonas Depoix.
For issues, feature requests, or contributions, please visit the GitHub Issues page.
Content type
Image
Digest
sha256:9a9e4e83e…
Size
47 MB
Last updated
11 months ago
docker pull oldgrandpavanu/youtubetranscriptapi