Open source Python library

YouTube downloads.
The Python way.

A powerful Python library and command line tool for downloading videos, audio, playlists and more. Simple to use. Built for developers.

$ pip install pytubefix
pytubefix — Python
# Import pytubefix
from pytubefix import YouTube

# Create a YouTube instance
yt = YouTube(url)

# Get video information
print(yt.title)

"Building Python Projects"

# Download highest resolution
yt.streams. get_highest_resolution()
   . download()

✓ Download completed
Built for developers
Python 3
⌘ Command line
A Async API
⚙ OAuth
FF FFmpeg

One library.
Multiple possibilities.

Everything you need to interact with YouTube content, whether you're building a Python application or working directly from your terminal.

▶

Video and audio downloads

Access progressive and adaptive streams, choose resolutions, download audio tracks and merge streams with FFmpeg when needed.

☰

Playlists and channels

Work with entire playlists and channels, control download limits and manage collections.

⌕

YouTube search

Search for videos and integrate results directly into your download workflow.

✎

Captions and subtitles

Retrieve available caption tracks and export subtitles in SRT format.

♪

Multiple audio languages

Select original audio or alternative language tracks when available.

⌘

Powerful command line interface

Use pytubefix directly from your terminal. Supports commands, options, pipelines, standard output, error handling and exit codes.

⚙

Async and OAuth

An asynchronous API and OAuth support for compatible restricted-content workflows.

Start building in minutes.

Install pytubefix and start working with YouTube content using a straightforward Python interface.

✦
Simple Python API Easy-to-understand examples to get your project started.
video.py
from pytubefix import YouTube
from pytubefix.cli import on_progress

yt = YouTube(
    url,
    on_progress_callback=on_progress
)

print(yt.title)

yt.streams.get_highest_resolution().download()
audio.py
from pytubefix import YouTube
from pytubefix.cli import on_progress

yt = YouTube(
    url,
    on_progress_callback=on_progress
)

yt.streams.get_audio_only().download()
playlist.py
from pytubefix import Playlist

playlist = Playlist(url)

for video in playlist.videos:

    video.streams.get_audio_only().download()

More power.
Right in your terminal.

A command line experience designed for developers who value automation, composability and Unix conventions.

Install pytubefix and access the CLI immediately. Use commands individually or combine them with your existing shell tools.
terminal
# Download a video
$ pytubefix "https://www.youtube.com/watch?v=VIDEO"

# Download audio in Portuguese
$ pytubefix -a --audio-track pt URL

# Download a playlist
$ pytubefix playlist -a -n 10 PLxxxx -o music/

# List available streams
$ pytubefix streams URL

# Export captions
$ pytubefix captions URL -c en > subtitles.srt

# Search and pipe results into downloads
$ pytubefix search "lofi" -n 3 | cut -f1 | pytubefix -a - -o music/
output
$ pytubefix playlist -a PLxxxx

[1/3] First song
↳ |████████████████████| 100%

[2/3] Second song
↳ |████████████████████| 100%

[3/3] Third song
↳ |██████████░░░░░░░░░░| 52.1%

$ echo $?

0

# Exit status
# 0   Success
# 1   Error
# 2   Usage error
# 130 Interrupted

Stay up to date.

Follow the latest stable release or explore the newest tagged version of pytubefix.

Latest stable Recommended
…
pip install -U pytubefix
Latest release candidate
…
pip install --pre -U pytubefix

Built in the open.

Explore the source, report issues or contribute to the pytubefix project.