youtube-unofficial

Access parts of your account unavailable through normal YouTube API access.

View on GitHub

youtube-unofficial

Python versions PyPI - Version GitHub tag (with filter) License GitHub commits since latest release (by SemVer including pre-releases) CodeQL QA Tests Coverage Status Dependabot Documentation Status mypy pre-commit Poetry pydocstyle pytest Ruff Downloads Stargazers Prettier

@Tatsh Buy Me A Coffee Libera.Chat Mastodon Follow Patreon

Access parts of your account unavailable through normal YouTube API access.

Installation

Poetry

poetry add youtube-unofficial

Pip

pip install youtube-unofficial

Usage

This uses a browser cookie storage to be able to access authorised endpoints. There is no feature to log in. You must be logged on in a supported browser. This supports any browser that yt-dlp supports.

Command line

Usage: youtube [OPTIONS] COMMAND [ARGS]...

  Unofficial YouTube CLI.

Options:
  -h, --help  Show this message and exit.

Commands:
  clear-watch-history          Clear watch history.
  clear-watch-later            Clear watch later queue.
  print-history                Print your watch history.
  print-playlist               Print a playlist.
  print-watch-later            Print your Watch Later playlist.
  remove-history-entries       Remove videos from Watch History.
  remove-video-id              Remove videos from a playlist.
  remove-watch-later-video-id  Remove videos from your Watch Later queue.
  toggle-watch-history         Disable or enable watch history

Every command takes a --debug or -d argument to show very verbose logs.

Some commands accept a -j/--json argument to print machine-readable output as JSON lines.

In Python

from youtube_unofficial import YouTubeClient

# Arguments are the browser name and profile.
yt = YouTubeClient('chrome', 'Default')

# Clear watch history
yt.clear_watch_history()

# Remove a single video ID from Watch Later queue
yt.remove_video_id_from_playlist('WL', video_id)

# Clear entire Watch Later queue
yt.clear_watch_later()

Contributing

For a new feature to be accepted, it must be something that cannot be achieved with Google’s official API. It also has to be on the youtube.com/youtu.be website or app and not a place like My Activity.

Code must run through yarn qa and have zero issues.