Skip to main content

Official Python SDK for YouTubeTranscript.dev — extract, transcribe, and translate YouTube video transcripts

Project description

YouTubeTranscript.dev

YouTubeTranscript Python SDK

Official Python client for the YouTubeTranscript.dev API
Extract, transcribe, and translate YouTube video transcripts.

PyPI version Python versions License


Installation

pip install youtubetranscriptdevapi

Quick Start

from youtubetranscript import YouTubeTranscript

yt = YouTubeTranscript("your_api_key")

# Extract transcript
result = yt.transcribe("dQw4w9WgXcQ")

print(f"Segments: {len(result.segments)}")
print(f"Duration: {result.duration:.0f}s")
print(f"Words: {result.word_count}")

for seg in result.segments[:5]:
    print(f"[{seg.start_formatted}] {seg.text}")

Get your free API key at youtubetranscript.dev/dashboard

Features

# Translate to any language
result = yt.transcribe("dQw4w9WgXcQ", language="es")

# Choose caption source
result = yt.transcribe("dQw4w9WgXcQ", source="manual")

# Format options
result = yt.transcribe("dQw4w9WgXcQ", format={"timestamp": True, "words": True})

# Batch — up to 100 videos at once
batch = yt.batch(["video1", "video2", "video3"])
for t in batch.completed:
    print(f"{t.video_id}: {t.word_count} words")

# ASR audio transcription (for videos without captions)
job = yt.transcribe_asr("video_without_captions")
result = yt.wait_for_job(job.job_id)  # polls until complete
print(result.text)

# Export formats
print(result.to_srt())       # SRT subtitles
print(result.to_vtt())       # WebVTT subtitles
print(result.to_plain_text())       # Plain text
print(result.to_timestamped_text()) # Text with timestamps

# Search within transcript
matches = result.search("keyword")

# Account stats
stats = yt.stats()
print(f"Credits: {stats.credits_remaining}")

# History
history = yt.list_transcripts(search="python tutorial", limit=5)

Async Client

import asyncio
from youtubetranscript import AsyncYouTubeTranscript

async def main():
    async with AsyncYouTubeTranscript("your_api_key") as yt:
        # Single
        result = await yt.transcribe("dQw4w9WgXcQ")

        # Concurrent
        results = await asyncio.gather(
            yt.transcribe("video1"),
            yt.transcribe("video2"),
            yt.transcribe("video3"),
        )

asyncio.run(main())

Error Handling

from youtubetranscript import YouTubeTranscript
from youtubetranscript.exceptions import (
    NoCaptionsError,
    AuthenticationError,
    InsufficientCreditsError,
    RateLimitError,
)

yt = YouTubeTranscript("your_api_key")

try:
    result = yt.transcribe("some_video")
except NoCaptionsError:
    # No captions — try ASR
    job = yt.transcribe_asr("some_video")
    result = yt.wait_for_job(job.job_id)
except AuthenticationError:
    print("Check your API key")
except InsufficientCreditsError:
    print("Top up at youtubetranscript.dev/pricing")
except RateLimitError as e:
    print(f"Rate limited — retry after {e.retry_after}s")

API Reference

YouTubeTranscript(api_key, *, base_url, timeout, max_retries)

Method Description
transcribe(video, *, language, source, format) Extract transcript
transcribe_asr(video, *, language, webhook_url) ASR audio transcription
get_job(job_id) Check ASR job status
wait_for_job(job_id, *, poll_interval, timeout) Poll until ASR completes
batch(video_ids, *, language) Batch extract (up to 100)
get_batch(batch_id) Check batch status
list_transcripts(*, search, language, status, limit, page) Browse history
get_transcript(video_id, *, language, source) Get saved transcript
stats() Account credits & usage
delete_transcript(*, video_id, ids) Delete transcripts

Transcript object

Property/Method Description
segments List of Segment objects
text Full transcript as string
video_id YouTube video ID
language Transcript language
word_count Total word count
duration Total duration in seconds
to_srt() Export as SRT
to_vtt() Export as WebVTT
to_plain_text() Plain text export
to_timestamped_text() Text with [MM:SS] timestamps
search(query) Find segments by text

Segment object

Property Description
text Segment text
start Start time (seconds)
end End time (seconds)
duration Duration (seconds)
start_formatted "MM:SS" format
start_hms "HH:MM:SS" format

Credit Costs

Operation Cost
Captions extraction 1 credit
Translation 1 credit per 2,500 chars
ASR audio transcription 1 credit per 90 seconds
Re-fetch owned transcript Free

License

MIT — see LICENSE

Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

youtubetranscriptdevapi-0.1.1.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

youtubetranscriptdevapi-0.1.1-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

Details for the file youtubetranscriptdevapi-0.1.1.tar.gz.

File metadata

  • Download URL: youtubetranscriptdevapi-0.1.1.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for youtubetranscriptdevapi-0.1.1.tar.gz
Algorithm Hash digest
SHA256 abd86a7c52db2ad56b96409ca0e4437fa7b7ad2ebe314bfd68f4da3cf7b20bdb
MD5 4c8d51c50ece2e663ddc4df68d86c128
BLAKE2b-256 8aeb21102a542c0031903fba198a2bb5795b7134a52d4a1d77a07b218aaa4217

See more details on using hashes here.

Provenance

The following attestation bundles were made for youtubetranscriptdevapi-0.1.1.tar.gz:

Publisher: publish.yml on Youtube-Transcript-Dev/youtube-transcript-python-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file youtubetranscriptdevapi-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for youtubetranscriptdevapi-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 46743494a02f602c08e175f691462bd493d16becea058543a671132b241ac6f7
MD5 cede5b3ec49e9d863e0781dd1f795b5d
BLAKE2b-256 64a764acca52788627c414b7ed99509b34c786fd08076b53c9ddf9e736dfa035

See more details on using hashes here.

Provenance

The following attestation bundles were made for youtubetranscriptdevapi-0.1.1-py3-none-any.whl:

Publisher: publish.yml on Youtube-Transcript-Dev/youtube-transcript-python-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page