TranscriptFetch Python SDK
Official, typed Python client for the TranscriptFetch API: fetch YouTube transcripts, channels, playlists, and search results as clean, structured data. Sync + async, fully type-hinted.
pip install transcriptfetch-sdk
Quickstart
from transcriptfetch import TranscriptFetch
tf = TranscriptFetch(api_key="tf_live_...")
t = tf.transcripts.video("https://youtu.be/aircAruvnKk")
print(t.title)
print(t.text)
for seg in t.segments:
print(f"[{seg.start:.1f}] {seg.text}")
print("credits left:", t.usage.balance)
Get an API key (100 free credits) at https://transcriptfetch.com/app. One credit per successful fetch; failed/blocked/no-transcript requests are free.
Endpoints
tf.transcripts.video(video)
tf.transcripts.channel(channel, limit=, cursor=)
tf.transcripts.playlist(playlist, limit=, cursor=)
tf.transcripts.search(query, limit=, cursor=)
tf.transcripts.batch(video_ids)
tf.health()
video/channel/playlist accept URLs or raw IDs (normalized automatically).
List endpoints are cursor-paginated. Iterate every result without managing cursors:
for video in tf.transcripts.iter_channel("@lexfridman", limit=10):
print(video.video_id, video.title)
Or page manually via page.next_cursor and the cursor= argument.
Async
import asyncio
from transcriptfetch import AsyncTranscriptFetch
async def main():
async with AsyncTranscriptFetch() as tf:
t = await tf.transcripts.video("aircAruvnKk")
print(t.text)
async for v in tf.transcripts.iter_search("how transformers work", limit=10):
print(v.title)
asyncio.run(main())
Errors
All errors subclass TranscriptFetchError. API errors carry .status, .code, .message, and .request_id:
from transcriptfetch import (
AuthenticationError, InsufficientCreditsError, InvalidRequestError,
RateLimitError, IdempotencyConflictError, UpstreamUnavailableError,
InternalServerError, APIError, APIConnectionError, APITimeoutError,
)
try:
tf.transcripts.video("bad")
except InsufficientCreditsError:
...
except RateLimitError as e:
print(e.retry_after)
except APIError as e:
print(e.status, e.code, e.request_id)
Reliability
- Automatic retries on
429 (honoring Retry-After) and 5xx, with exponential backoff + jitter (max_retries=2 by default).
- Idempotency: every write auto-sends an
Idempotency-Key so a retried request is never double-charged. Override per call with idempotency_key=....
- Configurable:
TranscriptFetch(api_key=..., base_url=..., timeout=30, max_retries=2). Both clients are context managers and accept a custom http_client= (httpx).
Development
pip install -e ".[dev]"
ruff check . && mypy src && pytest
Tests are fully mocked (no network). MIT licensed.