Registry / http-networking / pytube

pytube

JSON →
library15.0.0pypypi✓ verified 26d ago

Pytube is a Python 3 library designed for downloading YouTube videos and playlists. It handles various resolutions, formats, and audio-only extractions. Currently at version 15.0.0, it maintains an active release cadence, primarily updating to adapt to frequent changes in YouTube's frontend, which it scrapes to function.

pip install pytube
INSTALL
IMPORT
SIG · PYTUBE
P
pytube
http-networkingpythonv15.0.0
Install
1.8s avg
Import
213ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v15.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.216s · 18.2MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.8s · import 0.210s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

YouTube
from pytube import YouTube
Playlist
from pytube import Playlist
Search
from pytube import Search

This quickstart demonstrates how to initialize a YouTube object with a video URL and download the highest resolution stream to a local 'downloads' directory. It includes basic error handling.

from pytube import YouTube # Example: Download the highest resolution of a video video_url = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ' # Rick Astley - Never Gonna Give You Up try: yt = YouTube(video_url) print(f"Downloading: {yt.title}...") # Get the highest resolution stream stream = yt.streams.get_highest_resolution() # Or, filter by resolution and file extension # stream = yt.streams.filter(res="720p", file_extension='mp4').first() if stream: stream.download(output_path='./downloads') print(f"Successfully downloaded '{yt.title}' to ./downloads") else: print("No suitable stream found.") except Exception as e: print(f"An error occurred: {e}")
Debug
Known issues
breakingPytube relies on scraping YouTube's frontend, making it highly susceptible to breaking changes when YouTube updates its site. This often manifests as `KeyError`, `RegexMatchError`, `HTTPError` (404, 403), or `AgeRestrictedError`.
fix
Update `pytube` to the latest version immediately if you encounter download failures or errors. Check the GitHub repository for recent issues or workarounds.
affects: All versions are vulnerable to future YouTube updates. Specific patches are released frequently.
breakingSince version 11.0.0, downloading age-restricted videos explicitly requires user authentication. Attempts to download without authentication will raise an `AgeRestrictedError`.
fix
If you need to download age-restricted content, you must implement an OAuth flow (using `pytube.request.get_auth_gmt()`) to obtain necessary cookies for authentication. Refer to the `pytube` documentation for authentication examples.
affects: >= 11.0.0
gotchaPytube does not support downloading live streams. As of version 10.8.3, attempts to process a livestream URL will raise an exception (e.g., `LiveStreamError`).
fix
Ensure the URL points to a non-live video. There is no built-in `pytube` mechanism to download ongoing live streams.
affects: >= 10.8.3
gotchaYouTube occasionally implements download throttling mechanisms by obfuscating URL parameters (e.g., the 'n' cipher). While `pytube` actively releases updates to bypass this (e.g., v10.9.0), issues can recur.
fix
If download speeds are unusually slow or downloads fail, update `pytube` to the latest version. This issue is usually addressed quickly by the maintainers.
affects: Intermittent across all versions, typically fixed in subsequent releases.
Errors
Common errors & fixes
pytube.exceptions.RegexMatchError: get_throttling_function_name: could not find match for multiple patterns
Pytube's internal regular expressions, used to extract video information from YouTube's page source, are outdated due to changes in YouTube's frontend.
fix
Upgrade pytube to the latest version using `pip install --upgrade pytube` to get the updated regex patterns.
KeyError: 'cipher'
Pytube is unable to find an expected key in the parsed YouTube data, typically because YouTube has changed its internal data structure for video streams.
fix
Upgrade pytube to the latest version using `pip install --upgrade pytube`, as newer versions often include fixes for these YouTube changes.
ModuleNotFoundError: No module named 'pytube'
The `pytube` library has not been installed in the Python environment where the script is being executed.
fix
Install the library using pip: `pip install pytube`.
pytube.exceptions.VideoUnavailable: The video is unavailable.
The provided YouTube URL links to a video that is private, deleted, restricted by region, or otherwise not publicly accessible.
fix
Verify the video URL is correct and that the video is publicly available without restrictions (e.g., age or region).
Upgrade
Version history
15.0.0latest on PyPI · released May 7, 2023
Audit
Dependencies

No dependency data recorded yet.

Agent activity
18 hits · last 30 days
node
16
Resources
pytube — pip install pytube · libregistry