Metadata-Version: 2.5
Name: youtubetranscript-net
Version: 0.1.0
Summary: Python client for the YouTubeTranscript.net API: YouTube transcripts with timestamps.
Project-URL: Homepage, https://youtubetranscript.net
Project-URL: Documentation, https://youtubetranscript.net/docs/api
Project-URL: Repository, https://github.com/youtube-transcript/youtubetranscript-python
Project-URL: Issues, https://github.com/youtube-transcript/youtubetranscript-python/issues
License-Expression: MIT
License-File: LICENSE
Keywords: api,captions,subtitles,transcript,youtube
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Typing :: Typed
Requires-Python: >=3.9
Description-Content-Type: text/markdown

# youtubetranscript-net (Python)

Python client for the [YouTubeTranscript.net API](https://youtubetranscript.net/docs/api): get YouTube transcripts with timestamps, download them as TXT, SRT or VTT, and transcribe whole playlists and channels. Standard library only, Python 3.9+, fully typed.

## Install

```bash
pip install youtubetranscript-net
```

## Quick start

Create an API key at <https://youtubetranscript.net/account/api-keys> and set it as `YTT_API_KEY`.

```python
from youtubetranscript_net import YouTubeTranscript

client = YouTubeTranscript()  # reads YTT_API_KEY

result = client.transcripts.get("https://www.youtube.com/watch?v=jNQXAC9IVRw")
for segment in result.transcript.segments:
    print(segment.start, segment.text)
```

`get` waits for the transcript: it asks for a fast answer, and when the video needs more time (speech-to-text, long videos) it polls the job until it is done.

## Client options

```python
YouTubeTranscript(
    api_key="ytt_...",                            # default YTT_API_KEY
    base_url="https://api.youtubetranscript.net", # default YTT_BASE_URL, then this
    timeout=60.0,                                 # seconds per HTTP request
    max_retries=2,                                # automatic retries, see below
)
```

## Methods

`video` is a YouTube link (watch, youtu.be, Shorts) or an 11-character video id.

### Transcripts

| Method | Returns |
|---|---|
| `transcripts.get(video, language=, format=, include_timestamp=, send_metadata=, confirm_credits=, timeout=300, poll_interval=2)` | `TranscriptResult` once ready |
| `transcripts.submit(video, ..., wait_ms=)` | the first answer: `TranscriptResult` or `TranscriptJob` |
| `transcripts.job(job_id)` | `TranscriptResult` or `TranscriptJob` |
| `transcripts.info(video)` | video details and caption languages (free) |
| `transcripts.list(q=, lang=, sort=, page=, page_size=)` | `{"transcripts", "total", "page", "pageSize", "langs"}` |
| `transcripts.download(video_id, "srt", language=)` | the file as `str` (`txt`, `srt`, `vtt`, `json`, `md`) |
| `transcripts.delete(video_id, language=)` | `{"removed": True}` |

`language` is a priority list such as `"en"`, `"pt-BR,pt"`, `"auto"` (the video's own captions) or `"asr"` (speech-to-text when there are no captions). `format="text"` returns plain text in `result.text`.

`TranscriptResult` has `status`, `job_id`, `language`, `format`, `cached`, `length_seconds`, `length_text`, `transcript` (`platform`, `external_id`, `lang`, `origin`, `title`, `channel`, `duration_sec`, `segments`), `text`, `metadata` and `raw` (the full JSON).

### Batches

```python
batch = client.batches.create(playlist="https://www.youtube.com/playlist?list=...")
done = client.batches.wait(batch["id"])
with open("transcripts.zip", "wb") as f:
    f.write(client.batches.export(batch["id"], format="zip", files="srt"))
```

| Method | Returns |
|---|---|
| `batches.create(items=[...] \| playlist= \| channel=, language=, limit=, name=)` | the batch |
| `batches.get(batch_id, max_results=, page_token=)` | `{"batch", "items", "nextPageToken"}` |
| `batches.wait(batch_id, timeout=1800, poll_interval=3)` | the last `get` once completed or failed |
| `batches.export(batch_id, format="zip", files=, timestamps=)` | file bytes (`zip`, `csv`, `txt`, `json`, `srt`, `vtt`) |
| `batches.retry(batch_id)` | `{"batch", "retried", "credits"}` |
| `batches.delete(batch_id)` | `{"removed": True}` |

Batches are available once your account has bought a credit pack.

### Account

`client.account.usage()` returns your credits (`balance`, `freeToday`, `available`) and limits.

## Errors

Every failure raises `YouTubeTranscriptError`:

```python
from youtubetranscript_net import YouTubeTranscriptError

try:
    client.transcripts.get(video, language="de")
except YouTubeTranscriptError as e:
    e.code         # "LANGUAGE_NOT_AVAILABLE", "INSUFFICIENT_CREDITS", "RATE_LIMITED", ...
    e.status       # HTTP status, 0 for local errors
    e.message
    e.request_id   # X-Request-Id, include it when you contact support
    e.retry_after  # seconds, on 429
    e.details      # the server's error object, e.g. e.details["availableLanguages"]
    e.retryable    # True for 429, 5xx and network errors
```

A video that costs more than 10 credits raises `CREDITS_CONFIRMATION_REQUIRED` first; call again with `confirm_credits=True` to accept the cost.

## Retries

GET and DELETE requests, and `transcripts.get` / `submit` (sent with an `Idempotency-Key`, so the server never runs or charges them twice), are retried up to `max_retries` times on 429, 5xx and network errors, waiting for `Retry-After` when the server sends it. `batches.create` and `batches.retry` are never retried automatically.

## Development

```bash
python3 -m unittest discover -s tests                                   # unit tests, no network
YTT_API_KEY=ytt_... PYTHONPATH=src python3 examples/e2e.py              # end-to-end against the API
```
