{"id":8794,"library":"ytmusicapi","title":"YouTube Music API (Unofficial)","description":"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]","status":"active","version":"1.11.5","language":"en","source_language":"en","source_url":"https://github.com/sigma67/ytmusicapi","tags":["youtube","youtube-music","api","unofficial","music","audio","playlists"],"install":[{"cmd":"pip install ytmusicapi","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"YTMusic","correct":"from ytmusicapi import YTMusic"}],"quickstart":{"code":"import os\nfrom ytmusicapi import YTMusic\n\n# --- Authentication (choose one) ---\n# Option 1: Using browser headers (recommended for personal use)\n# Create 'browser.json' by following instructions in the ytmusicapi documentation (developer tools network tab -> copy as cURL).\n# For programmatic setup, use `from ytmusicapi.auth.browser import setup_browser`\n# Example: yt = YTMusic('browser.json')\n\n# Option 2: Using OAuth (requires Google Cloud Project setup, often more stable for automated scripts)\n# Create 'oauth.json' by following instructions in the ytmusicapi documentation (Google Cloud Console -> OAuth client ID).\n# Example: yt = YTMusic('oauth.json')\n\n# For unauthenticated requests (limited functionality):\nyt = YTMusic()\n\n# Use an environment variable for the auth file path in production\nauth_file = os.environ.get('YTMUSIC_AUTH_FILE', 'oauth.json') # or 'browser.json'\n\ntry:\n    yt = YTMusic(auth_file)\n    # Perform a search\n    search_results = yt.search('Eminem Lose Yourself', filter='songs')\n    if search_results:\n        print(f\"Found song: {search_results[0]['title']} by {search_results[0]['artist']['name']}\")\n    else:\n        print(\"No results found.\")\n\n    # Get library playlists\n    playlists = yt.get_library_playlists(limit=5)\n    if playlists:\n        print(\"\\nYour first 5 library playlists:\")\n        for playlist in playlists:\n            print(f\"- {playlist['title']} (ID: {playlist['playlistId']})\")\n    else:\n        print(\"No library playlists found.\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n    print(\"Please ensure your authentication file (oauth.json or browser.json) is correctly set up and accessible.\")","lang":"python","description":"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]"},"warnings":[{"fix":"Upgrade to Python 3.10 or newer. Use `pip install --upgrade python` (or your system's Python management tool) and then `pip install ytmusicapi`.","message":"Older Python versions (e.g., Python 3.6) are not supported by recent `ytmusicapi` versions (>= 0.24.0). The `ytmusicapi` CLI tool, including for OAuth setup, was introduced in version 1.0.0, requiring Python 3.10 or higher. [18]","severity":"breaking","affected_versions":"< 1.0.0 (for CLI), < 0.24.0 (for library)"},{"fix":"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]","message":"OAuth authentication can intermittently fail with a 'HTTP 400: Bad Request' error. This often occurs seemingly at random or after a period of working correctly. [15, 17]","severity":"gotcha","affected_versions":"All versions, intermittent"},{"fix":"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]","message":"The `YTMusic.setup()` method was used in older versions for setting up browser authentication. While it might still be present, the documentation now emphasizes direct initialization with the auth file or using `ytmusicapi.auth.browser.setup_browser` for programmatic header parsing. [6, 14, 19]","severity":"deprecated","affected_versions":"< 1.0.0"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"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.","cause":"The `ytmusicapi` command-line interface (CLI) was introduced in version 1.0.0. If you are on an older Python version (e.g., Python 3.6) that pulls an older `ytmusicapi` version, the CLI will not be available. Also, ensure `~/.local/bin` is in your PATH. [18]","error":"ytmusicapi: command not found"},{"fix":"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]","cause":"This error typically indicates an issue with the authentication credentials, particularly when using OAuth. The provided `oauth.json` might be invalid, expired, or YouTube Music's API might be rejecting the request for an unknown reason. [15, 17]","error":"ytmusicapi.exceptions.YTMusicServerError: Server returned HTTP 400: Bad Request. Request contains an invalid argument."}]}