YTMusic

class ytmusicapi.YTMusic(auth: str | dict | None = None, user: str | None = None, requests_session=True, proxies: dict[str, str] | None = None, language: str = 'en', location: str = '', oauth_credentials: OAuthCredentials | None = None)

Allows automated interactions with YouTube Music by emulating the YouTube web client’s requests. Permits both authenticated and non-authenticated requests. Authentication header data must be provided on initialization.

YTMusic.__init__(auth: str | dict | None = None, user: str | None = None, requests_session=True, proxies: dict[str, str] | None = None, language: str = 'en', location: str = '', oauth_credentials: OAuthCredentials | None = None)

Create a new instance to interact with YouTube Music.

Parameters:
  • auth – Optional. Provide a string, path to file, or oauth token dict. Authentication credentials are needed to manage your library. See setup() for how to fill in the correct credentials. Default: A default header is used without authentication.

  • user – Optional. Specify a user ID string to use in requests. This is needed if you want to send requests on behalf of a brand account. Otherwise the default account is used. You can retrieve the user ID by going to https://myaccount.google.com/brandaccounts and selecting your brand account. The user ID will be in the URL: https://myaccount.google.com/b/user_id/

  • requests_session

    A Requests session object or a truthy value to create one. Default sessions have a request timeout of 30s, which produces a requests.exceptions.ReadTimeout. The timeout can be changed by passing your own Session object:

    s = requests.Session()
    s.request = functools.partial(s.request, timeout=3)
    ytm = YTMusic(requests_session=s)
    

    A falsy value disables sessions. It is generally a good idea to keep sessions enabled for performance reasons (connection pooling).

  • proxies

    Optional. Proxy configuration in requests format.

  • language – Optional. Can be used to change the language of returned data. English will be used by default. Available languages can be checked in the ytmusicapi/locales directory.

  • location – Optional. Can be used to change the location of the user. No location will be set by default. This means it is determined by the server. Available languages can be checked in the FAQ.

  • oauth_credentials – Optional. Used to specify a different oauth client to be used for authentication flow.