Skip to main content

Official Python SDK for the FetchTranscript YouTube API

Project description

FetchTranscript Python SDK

Official Python SDK for the FetchTranscript API — fetch YouTube transcripts, video metadata, channel info, and more.

Installation

pip install fetchtranscript

Quick Start

from fetchtranscript import FetchTranscriptClient

client = FetchTranscriptClient(api_key="yt_your_api_key")

# Get a transcript
transcript = client.transcripts.get("dQw4w9WgXcQ")
for segment in transcript["segments"]:
    print(f"[{segment['start']:.1f}s] {segment['text']}")

# Get video metadata
video = client.videos.get_metadata("dQw4w9WgXcQ")
print(video["title"])

Async Usage

import asyncio
from fetchtranscript import AsyncFetchTranscriptClient

async def main():
    async with AsyncFetchTranscriptClient(api_key="yt_your_api_key") as client:
        transcript = await client.transcripts.get("dQw4w9WgXcQ")
        print(transcript["language"])

asyncio.run(main())

API Reference

Transcripts

# Get transcript (JSON format with segments)
transcript = client.transcripts.get("VIDEO_ID")

# Get transcript in a specific language
transcript = client.transcripts.get("VIDEO_ID", lang="es")

# Get as plain text
text = client.transcripts.get_text("VIDEO_ID")

# Get as SRT subtitles
srt = client.transcripts.get_srt("VIDEO_ID")

# List available languages
languages = client.transcripts.list_languages("VIDEO_ID")

Videos

# Get video metadata
metadata = client.videos.get_metadata("VIDEO_ID")

# Get video chapters
chapters = client.videos.get_chapters("VIDEO_ID")

# Get video comments
comments = client.videos.get_comments("VIDEO_ID", limit=50)

Channels

# Get channel info
channel = client.channels.get_info("CHANNEL_ID")

# Get channel videos
videos = client.channels.get_videos("CHANNEL_ID", limit=20)

# Get all videos with auto-pagination
all_videos = client.channels.get_all_videos("CHANNEL_ID")

Search

# Search videos
results = client.search.videos("python tutorial", limit=10)

# Search and check transcript availability
results = client.search.find_videos_with_transcripts("python tutorial")

Error Handling

The SDK raises domain-specific exceptions instead of raw HTTP errors:

from fetchtranscript import (
    FetchTranscriptClient,
    VideoNotFoundError,
    InsufficientCreditsError,
    AuthenticationError,
)

client = FetchTranscriptClient(api_key="yt_your_api_key")

try:
    transcript = client.transcripts.get("invalid_id")
except VideoNotFoundError as e:
    print(f"Video not found: {e.message}")
except InsufficientCreditsError:
    print("Not enough credits")
except AuthenticationError:
    print("Invalid API key")

Exception Hierarchy

Exception HTTP Status Description
FetchTranscriptError Base exception
VideoNotFoundError 404 Video not found or transcripts disabled
ChannelNotFoundError 404 Channel not found
InvalidVideoIdError 400 Invalid video/channel ID format
InsufficientCreditsError 402 Not enough credits
AuthenticationError 401 Missing or invalid API key
ServiceUnavailableError 503 Upstream service unavailable

Response Headers

After each request, you can check:

client.transcripts.get("dQw4w9WgXcQ")
print(client.credits_remaining)    # Remaining API credits
print(client.processing_time_ms)   # Processing time in ms

License

MIT

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

fetchtranscript-0.1.2.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

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

fetchtranscript-0.1.2-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file fetchtranscript-0.1.2.tar.gz.

File metadata

  • Download URL: fetchtranscript-0.1.2.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for fetchtranscript-0.1.2.tar.gz
Algorithm Hash digest
SHA256 c82c5d2d8a69179b4ee126641112ab30b16935185ed1e7c88ccf3105ac10145d
MD5 7129cc1772708f8a989ac0d3a745e808
BLAKE2b-256 e429e23e9c67f0f53a70071b3f9748d48e81c7623757f244ec5393e03e00837e

See more details on using hashes here.

File details

Details for the file fetchtranscript-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for fetchtranscript-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 445ac20c3efa7af136c80df50d465a5addb8e43afd0fc7c2553e9608a8f19f57
MD5 4f1047f44813c2391f6b7cdc30982d30
BLAKE2b-256 bc7fcb16014ba47d393ee9931669461c4bf6847fe71b392dc8c72e87f4dd4196

See more details on using hashes here.

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