ytdlp.org

Practical yt-dlp docs: install, commands, fixes, cookies, and workflows.

Current section

Workflow guide

How to use yt-dlp as an API

yt-dlp is a command-line tool and a Python library — it has no official HTTP API. If your app, backend, or automation needs to turn a video URL into a file programmatically, you have three real options, each with different costs. This guide covers all three honestly.

Quick answer

  • Python project? Import yt-dlp directly as a library — no API needed.
  • Other language, low volume? Shell out to the CLI and parse --dump-json output.
  • Production service, real volume? Either build and babysit your own wrapper service, or use a managed media-import API and skip the maintenance.

Option 1: Embed yt-dlp as a Python library

If your code is Python, you do not need an API at all. yt-dlp is on PyPI and is designed to be imported:

import yt_dlp

opts = {
    "format": "bestvideo*+bestaudio/best",
    "outtmpl": "%(uploader)s/%(title)s.%(ext)s",
}

with yt_dlp.YoutubeDL(opts) as ydl:
    info = ydl.extract_info(url, download=True)
    print(info["title"], info["duration"])

Use download=Falseto fetch metadata only. This is the cleanest integration — full access to formats, progress hooks, and postprocessors. The catch: your process now owns yt-dlp's failure modes (extractor breakage, IP blocks, updates), and downloads are long-running and CPU/network heavy, so you will end up adding a job queue anyway.

Option 2: Shell out to the CLI from any language

From Node, Go, Rust, PHP, or anything else, spawn the binary. The flag that makes this workable is -J / --dump-json, which prints machine-readable metadata instead of downloading:

# Metadata only, as JSON
yt-dlp -J "URL"

# Download and print the final filepath for your program to pick up
yt-dlp -o "%(id)s.%(ext)s" --print after_move:filepath "URL"

Watch out for: non-zero exit codes on partial playlist failures, output that mixes progress and warnings on stderr, and the yt-dlp binary needing regular updates on whatever machine runs this. Fine for internal tools and low volume; brittle as a product dependency.

Option 3: Wrap it in your own HTTP service

The classic build: a small FastAPI/Express app that accepts a URL, runs yt-dlp in a worker, and returns a file or a storage link. A minimal sketch:

from fastapi import FastAPI
import yt_dlp

app = FastAPI()

@app.post("/import")
def import_media(url: str):
    with yt_dlp.YoutubeDL({"outtmpl": "/data/%(id)s.%(ext)s"}) as ydl:
        info = ydl.extract_info(url, download=True)
    return {"id": info["id"], "title": info["title"]}

That sketch works in a demo and falls over in production. Before trusting it, you need: a job queue (downloads take minutes), disk cleanup, concurrency limits, retry logic, a strategy for datacenter IP blocks, cookie management for gated content, and a cron job updating yt-dlp before extractor breakage takes you down. Budget for ongoing maintenance, not a weekend project.

Option 4: Use a managed media-import API

If the download capability is part of a product — a SaaS feature, an AI pipeline, a no-code automation — the honest comparison is build-vs-buy. A managed API like Importly does the same job as the wrapper service above — public link in, usable media out — but the extractor maintenance, IP rotation, rate limiting, and retries are someone else's pager. You get webhook or direct-to-S3 delivery instead of managing disks. The trade-off is a per-import cost and an external dependency, which is why self-hosting still makes sense for personal tools and unusual requirements.

For builders

Using yt-dlp inside an app or script?

Paste a link to see what a managed media-import API returns — no install, no signup.

Which option fits your case

  • • personal scripts and internal tools → library or CLI, keep it simple
  • • Python app, modest volume, tolerant of breakage → library + a job queue
  • • product feature, paying users, or AI pipeline at volume → managed API, or a wrapper service with real ops investment
  • • anything running on cloud IPs at scale → read the server guide first; IP blocking changes the math

Straightforward yt-dlp help for installs, commands, fixes, cookies, and repeatable workflows.

ytdlp.org is an independent, community-maintained documentation site. It is not affiliated with the yt-dlp project — the official source code lives at github.com/yt-dlp/yt-dlp.