Home / Use cases / Get a YouTube Transcript in Python

Updated

Get a YouTube Transcript in Python (with Timestamps)

You want transcripts inside a Python script or notebook, with timestamps for citations, and code that keeps working when it runs on a server.

Try it now on Apify YouTube Transcript for AI: RAG Chunks, Chapters, SRT · $0.002 per one video whose transcript was returned · failed items are free

How to do it, step by step

  1. pip install apify-client and create a free Apify token (Settings > API & Integrations).
  2. Call the Actor with the code below; segments gives start times in seconds for each caption.
  3. Iterate over the dataset items; each one is a video with status, text, segments and chapters.
  4. Store the videoId with your data so you can link back to https://youtu.be/ID?t=SECONDS.
from apify_client import ApifyClient

client = ApifyClient("YOUR_APIFY_TOKEN")
run = client.actor("plainprobe/youtube-transcript-ai").call(
    run_input={"videos": ["https://www.youtube.com/watch?v=zjkBMFhNj_g"], "includeChunks": False})
for video in client.dataset(run["default_dataset_id"]).iterate_items():
    print(video["status"], video["title"], video["wordCount"])
    for seg in video["segments"][:3]:
        print(seg["start"], seg["text"])

The exact input used for the example below:

{
  "videos": [
    "https://www.youtube.com/watch?v=zjkBMFhNj_g"
  ],
  "includeChunks": false
}

Real result

Run Z3Mslzd6t1AcxcAnd on 2026-12-05: status SUCCEEDED, 1 item(s), 2.6 s of run time. Output shortened for reading (long text cut with “…”).

1,704 timestamped segments came back with the text, in 2.6 s of run time.

[
  {
    "videoId": "zjkBMFhNj_g",
    "title": "[1hr Talk] Intro to Large Language Models",
    "durationSeconds": 3588,
    "wordCount": 12151,
    "chapters": [
      {
        "start": 0,
        "title": "Intro: Large Language Model (LLM) talk",
        "end": 20
      },
      {
        "start": 20,
        "title": "LLM Inference",
        "end": 257
      },
      {
        "start": 257,
        "title": "LLM Training",
        "end": 538
      },
      "… 18 more"
    ],
    "segments": [
      {
        "start": 0.16,
        "dur": 4.08,
        "text": "hi everyone so recently I gave a"
      },
      {
        "start": 2.28,
        "dur": 4.119,
        "text": "30-minute talk on large language models"
      },
      {
        "start": 4.24,
        "dur": 4.24,
        "text": "just kind of like an intro talk um"
      },
      "… 1701 more"
    ]
  }
]

Try it now with your own input

FAQ

Is there a free option?

The open-source youtube-transcript-api package is free and fine on a home connection. The Actor is the paid option for servers and batches; the first 100 transcripts per Apify account are free until 31 January 2027.

Can I call it asynchronously?

Yes: client.actor(...).start() returns at once; read the dataset when the run finishes, or use a webhook.

What do segments look like?

Each segment has start and end in seconds and the caption text, so you can cite an exact moment.

Related