What Is yt-dlp? Python Library and CLI Guide
yt-dlp is a command-line video and audio downloader you can also import as a Python library. Install it, see working code, and what it needs.
yt-dlp is a command-line program that downloads video and audio from YouTube and thousands of other sites, and it is also a Python library you can import into your own code. The package is named yt-dlp, you run it as yt-dlp, and in Python you import yt_dlp. It needs Python 3.11 or newer: its README says it supports only 3.11+ and drops older versions as they reach end of life.
The Python version, in short:
from yt_dlp import YoutubeDL
with YoutubeDL() as ydl:
ydl.download(["https://www.youtube.com/watch?v=example"])That is the whole API for a basic download. Options, metadata without downloading and audio extraction are in Using yt-dlp in Python below. The Python examples in this guide were run with yt-dlp 2026.10.26 on Python 3.13 against a local audio file, using yt-dlp’s generic extractor: extract_info, sanitize_info, download, a progress hook and audio extraction through ffmpeg all worked. They were not run against YouTube, whose behaviour changes often.
Install it
python -m pip install -U "yt-dlp[default]"The default extra pulls in the optional packages the project recommends. Two other things matter in practice:
- ffmpeg and ffprobe. Needed to merge separate video and audio streams and for post-processing such as converting to MP3. They have to be the real programs, not the Python package with the same name as ffmpeg.
- A JavaScript runtime. The project’s README says full YouTube support needs the
yt-dlp-ejscomponent plus a runtime such as Deno (recommended), Node.js, Bun or QuickJS. Without one, some YouTube downloads may not work.
Sites change constantly, so yt-dlp breaks and gets fixed often. Keep it updated: it warns when your version is more than 90 days old, and the maintainers ask you to try the nightly release (python -m pip install -U --pre "yt-dlp[default]") before reporting a bug against stable.
What it does on the command line
yt-dlp "https://www.youtube.com/watch?v=example" # download best quality
yt-dlp -x --audio-format mp3 "https://..." # extract audio only
yt-dlp -f "bestvideo[height<=720]+bestaudio" "https://..." # specific qualityyt-dlp handles format selection (specific resolutions, audio-only extraction, container formats), subtitle downloading, playlist handling, and metadata extraction across a very large list of supported sites, not just YouTube.
Using yt-dlp in Python
The basic pattern is a YoutubeDL object in a with block:
from yt_dlp import YoutubeDL
URLS = ["https://www.youtube.com/watch?v=example"]
with YoutubeDL() as ydl:
ydl.download(URLS)Get information without downloading
Pass download=False to extract_info() to inspect a video’s title, formats and duration first. sanitize_info() turns the result into something you can safely serialise to JSON:
import json
import yt_dlp
with yt_dlp.YoutubeDL({}) as ydl:
info = ydl.extract_info("https://www.youtube.com/watch?v=example", download=False)
print(json.dumps(ydl.sanitize_info(info)))Note that the return value of extract_info() is dictionary-like but not guaranteed to be a plain JSON-serialisable dictionary, which is why sanitize_info() exists.
Extract audio
Options go in a dictionary. Post-processing, such as pulling out the audio track, is done with the postprocessors list and needs ffmpeg:
import yt_dlp
ydl_opts = {
"format": "m4a/bestaudio/best",
"postprocessors": [{"key": "FFmpegExtractAudio", "preferredcodec": "m4a"}],
}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
ydl.download(["https://www.youtube.com/watch?v=example"])Report progress
A progress_hooks function is called as the download advances, which is how you build a progress bar or log a result:
def my_hook(d):
if d["status"] == "finished":
print("Done downloading, now post-processing ...")
ydl_opts = {"progress_hooks": [my_hook]}Turn command-line flags into options
If you already know the command-line switches, the repository includes devscripts/cli_to_api.py, which translates a set of CLI switches into the matching YoutubeDL options. For the full list of options, run help(yt_dlp.YoutubeDL) in a Python shell.
If you need output from the command-line program instead of the library, don’t parse its normal text output, which may change between versions. Use options such as -J, --print or --progress-template to produce output you can rely on.
How it relates to youtube-dl
yt-dlp is a fork of the older youtube-dl project, based on the now-inactive youtube-dlc, created to add features and merge fixes faster than the original project’s maintenance pace allowed. It’s the more actively maintained of the two: yt-dlp’s latest release on PyPI is 2026.10.26 (26 October 2026), while youtube-dl’s last PyPI release was 2021.12.17 (16 December 2021). If you are porting code from youtube-dl, the main difference to watch for is that extract_info()’s return value is not guaranteed to be a plain dictionary, so pass it through sanitize_info() before serialising it.
The legal note worth being clear about
The tool itself is legal, open-source software with legitimate uses (archiving your own content, downloading material you have rights to, working with permissively-licensed video). Whether downloading any specific piece of content is permitted depends on that content’s copyright status and the platform’s terms of service. The tool doesn’t change what’s legally permissible to download and redistribute.
Frequently Asked Questions
What is yt-dlp used for?
Downloading video and audio from YouTube and thousands of other supported sites, from the command line or as a Python library — selecting specific formats and qualities, extracting audio only, downloading subtitles, and more.
What is the difference between yt-dlp and yt_dlp?
They are the same project. The package and command are named yt-dlp (with a hyphen), but Python module names can’t contain hyphens, so in code you write import yt_dlp. Install with pip install yt-dlp, run it as yt-dlp, and import it as yt_dlp.
How do I use yt-dlp in a Python script?
Install it with pip, import YoutubeDL from yt_dlp, and call download() with a list of URLs inside a with block. Pass a dictionary of options (the same ideas as the command-line flags) to control the format, output name and post-processing, or call extract_info(url, download=False) to inspect a video’s metadata without downloading it.
Does yt-dlp need ffmpeg?
Not always, but it is strongly recommended. ffmpeg is required to merge separate video and audio streams into one file and for post-processing such as converting to MP3 or extracting audio. It must be the ffmpeg program itself, not the Python package of the same name.
Is yt-dlp legal to use?
The tool itself is legal open-source software; whether downloading a specific video is permitted depends on that content’s terms of service and copyright status. Downloading content you don’t have rights to distribute or reuse can violate the platform’s terms or copyright law, regardless of the tool used.
How is yt-dlp different from youtube-dl?
yt-dlp is a fork of the older youtube-dl project, based on the now-inactive youtube-dlc, created to add features and fixes faster than the original project’s maintenance pace allowed. It is the more actively maintained option: its latest PyPI release is dated 26 October 2026, while youtube-dl’s last PyPI release was in December 2021.