ytmusicapi is a Python 3 library that provides an unofficial API for interacting with YouTube Music. It emulates web client requests using user cookie data for authentication, allowing for browsing, library management, playlist manipulation, and more. The current version is 1.11.5 and it maintains an active release cadence with frequent updates. [1, 7]
pip install ytmusicapiVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize `ytmusicapi` for both authenticated and unauthenticated requests. It shows a basic search for a song and retrieving the first few library playlists. Authentication typically requires either an `oauth.json` or `browser.json` file, which should be generated by following the detailed steps in the official ytmusicapi documentation. For a secure production environment, the path to this authentication file should be managed via environment variables. [1, 2, 3, 4]
Upgrade to Python 3.10 or newer. Use `pip install --upgrade python` (or your system's Python management tool) and then `pip install ytmusicapi`.
If encountering frequent '400 Bad Request' errors with OAuth, switch to browser-based authentication (using `browser.json`). Ensure your `oauth.json` is correctly generated, or regenerate it if the issue persists. Often, browser auth proves more robust for personal use. [15]
For new projects or updating existing ones, directly pass the path to `browser.json` or `oauth.json` to the `YTMusic()` constructor. Refer to the current documentation for the latest recommended setup procedures, especially `from ytmusicapi.auth.browser import setup_browser` for generating the browser.json programmatically from cURL headers. [14]
Upgrade Python to 3.10 or higher and reinstall `ytmusicapi` (`pip install --upgrade ytmusicapi`). Verify `~/.local/bin` is in your system's PATH environment variable for the executable to be found.
Try generating a new `oauth.json` file by re-running the OAuth authentication flow. If the problem persists, consider switching to browser authentication (`browser.json`) as a more stable alternative for some use cases. [15]
No dependency data recorded yet.