Skip to main content

yt-transcript-fetcher | YouTube Transcript Fetcher

Run Tests PyPI - Version PyPI - Python Version PyPI - License PyPI - Downloads

A python package to fetch YouTube video transcripts.

Installation

Use the package manager pip to install yt-transcript-fetcher.

pip install yt-transcript-fetcher

Usage

Basic usage examples can be found in the examples directory.

Command Line Interface (CLI)

The package includes a basic command line interface for fetching transcripts. You can run the following command:

yt-transcript-fetcher list-languages <video_id>

This will list all available languages for the specified video ID.

yt-transcript-fetcher download -l <language_code> <video_id>

This will download the transcript for the specified video ID in the given language code and output it to standard output.

Python API

You can also use the package as a Python module. Here is a basic example:

from yt_transcript_fetcher import list_languages, get_transcript
video_id = "dQw4w9WgXcQ"  # Replace with your video ID
languages = list_languages(video_id)
print("Available languages:", languages)
transcript = get_transcript(video_id, language="en")
print(transcript.text)
for segment in transcript.segments:
    print(segment.start_ms, segment.end_ms, segment.text)

Backend and compatibility

The package discovers caption languages through YouTube's internal player endpoint and fetches transcript text through get_panel using protobuf parameters. It needs only Python and the existing package dependencies: no browser, JavaScript helper, cookies, API key, or caption-URL download.

The public functions, YouTubeTranscriptFetcher(session=None), model constructors, timing helpers, and CLI commands remain unchanged. Existing legacy response parsers and protobuf helpers remain available. A fetcher caches language discovery per video and respects caller-supplied sessions. If multiple tracks share a language code, the first matching track retains precedence.

YouTube's modern panel groups text differently, so segment counts, text grouping, and timing boundaries can differ from older transcripts. Times remain in milliseconds on start_ms/end_ms, and seconds on start/end. The parser checks the returned video and caption track and rejects incomplete or malformed timing data instead of returning an incorrectly labelled transcript.

Unavailable videos and missing languages retain the existing named errors. Protocol failures raise YouTubeAPIError from yt_transcript_fetcher.exceptions. Rate-limit and server HTTP failures propagate as requests.HTTPError after retries; they are no longer misreported as missing videos. Default sessions retry transient failures and HTTP 429, respecting Retry-After, but do not retry HTTP 400 precondition failures.

Breaking error-contract migration

The transcript fix on fix/modern-transcript-panel retains the previous errors and retry policy. This branch, feat/transcript-error-contract, adds these changes for the subsequent major release:

Condition Previous behavior New behavior
Discovery HTTP failure other than 404/precondition VideoNotFoundError requests.HTTPError
Discovery connection failure/timeout Wrapped in Exception Original requests exception
Transcript HTTP 400 FAILED_PRECONDITION requests.HTTPError YouTubeAPIError
Invalid JSON/API response or missing panel Decode, availability, or missing-segment error YouTubeAPIError
HTTP 400 retry Retried by default Not retried

Update error handlers to catch requests.RequestException for transport failures and YouTubeAPIError for protocol failures. Discovery HTTP 404 and unplayable videos still raise VideoNotFoundError; missing languages still raise NoTranscriptError. Caller-supplied session retry configuration is kept.

This uses an undocumented API and may need updates as YouTube changes. Successful requests do not establish the rate limit on a Discord bot's hosting network; cache transcripts and bound concurrency in the application. The protocol and verification evidence are recorded in research/README.md.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

Metadata

Release files for yt-transcript-fetcher 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for yt-transcript-fetcher 2.0.0
File Size Uploaded Provenance
yt_transcript_fetcher-2.0.0.tar.gz 120.9 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for yt-transcript-fetcher 2.0.0
File Interpreter ABI Platform
yt_transcript_fetcher-2.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 140.7 kB

Release files / yt_transcript_fetcher-2.0.0.tar.gz

Download URL yt_transcript_fetcher-2.0.0.tar.gz
Size 120.9 kB
Tags Source
SHA-256 checksum
How to use checksums
5e97c73c7cc56e901db2b702874c1ff1e1c8afc24aece2ad7ed0ae38cbe077a2
BLAKE2b-256 checksum
How to use checksums
c63e7bce12ea2babe5e52a0c8cf76b664104991ba4a30ca6fab1616c6251115a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 21, 2026.

Transparency log

Release files / yt_transcript_fetcher-2.0.0-py3-none-any.whl

Download URL yt_transcript_fetcher-2.0.0-py3-none-any.whl
Size 19.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
687c1789ceed20f485141f0ad2bd1d1116db36b21b6ac0d3320d227b8051c030
BLAKE2b-256 checksum
How to use checksums
a985f900bbebf5cda1c88e3e8722d5bf5e69b970aae7e454311d954c22ec4e4e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 21, 2026.

Transparency log

Security for yt-transcript-fetcher 2.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for yt_transcript_fetcher-2.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 21, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page