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.1

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.1
File Size Uploaded Provenance Actions
yt_transcript_fetcher-2.0.1.tar.gz 122.4 kB With provenance Details for yt_transcript_fetcher-2.0.1.tar.gz

Built distribution (wheel)

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

Total release size: 142.5 kB

Release files / yt_transcript_fetcher-2.0.1.tar.gz

Download URL yt_transcript_fetcher-2.0.1.tar.gz
Size 122.4 kB
Tags Source
SHA-256 checksum
How to use checksums
39066b8049d593a1172d35ac413377cd74608e0d07e96ac06b82cec1313cfb4b
BLAKE2b-256 checksum
How to use checksums
1a599257907c8452ebd55e6ffc301ddcbd1e1c35af4f13c3eafd0368a8bd758a
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 Nov 5, 2026.

Transparency log

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

Download URL yt_transcript_fetcher-2.0.1-py3-none-any.whl
Size 20.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b7b163a475766e839a8a67d48b700360b3eae82bc9ffab1dde803f2c83d66fe5
BLAKE2b-256 checksum
How to use checksums
688c0a47cb4d2eab93ad10b89322b764b81a98d6af5d9439c47a255d5bcc0de0
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 Nov 5, 2026.

Transparency log

Security for yt-transcript-fetcher 2.0.1

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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for yt_transcript_fetcher-2.0.1.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 Nov 5, 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