Usage

Installation

Use pip: $ pip install gmusicapi. This will grab all the source dependencies. Avoid using easy_install.

If you’re upgrading from a date-versioned release (eg 2013.03.04), do $ pip uninstall gmusicapi; pip install gmusicapi instead.

If you’re going to be uploading music, you’ll likely need avconv or ffmpeg installed and in your system path, along with at least libmp3lame.

  • Linux
    • Use your distro’s package manager: e.g $ sudo apt-get install libav-tools libavcodec-extra-53 (ffmpeg requires extra steps on Debian/Ubuntu).
    • Download pre-built binaries of avconv or ffmpeg and edit your path to include the directory that contains avconv/ffmpeg.
  • Mac
  • Windows
    • Download pre-built binaries of avconv or ffmpeg and edit your path to include the directory that contains avconv.exe/ffmpeg.exe.
  • Google App Engine

The only time avconv or ffmpeg is not required is when uploading mp3s without scan-and-match enabled.

If you need to install avconv/ffmpeg from source, be sure to use $ ./configure --enable-gpl --enable-nonfree --enable-libmp3lame.

Quickstart

If you’re not going to be uploading music, you’ll likely want to use the Mobileclient: it supports streaming and library management. It requires plaintext auth, so your code might look something like:

from gmusicapi import Mobileclient

api = Mobileclient()
logged_in = api.login('user@gmail.com', 'my-password')
# logged_in is True if login was successful

Note that 2-factor users will need to setup and provide an app-specific password.

If you’re going to upload Music, you want the Musicmanager. It uses OAuth2 and does not require plaintext credentials.

Instead, you’ll need to authorize your account once before logging in. The easiest way is to run:

from gmusicapi import Musicmanager

mm = Musicmanager()
mm.perform_oauth()

If successful, this will save your credentials to disk. Then, future runs can start with:

from gmusicapi import Musicmanager

mm = Musicmanager()
mm.login()

# mm.upload('foo.mp3')
# ...

If you need both library management and uploading, just create multiple client instances.

There is also the Webclient, which is a mostly-deprecated interface. It is not tested nor well supported. Use Mobileclient or Musicmanager if possible.

The reference section has complete information on all clients: