Package: discogs-api
Discogs API ClientThis is a Python interface to the DiscogsREST API. It is intended as a drop-in replacement for the now deprecateddiscogs-client(GitHub,PyPi). Pull requests are welcome!It enables you to query the Discogs database for information on artists, releases, labels, users, Marketplace listings, and more. It also supports OAuth 1.0a authorization, which allows you to change user data such as profile information, collections and wantlists, inventory, and orders.InstallationInstall the client from PyPI using your favorite package manager.pipinstalldiscogs_apiQuickstartInstantiating the client object>>>importdiscogs_api>>>d=discogs_api.Client('ExampleApplication/0.1')Authorization (optional)There are a couple of different authorization methods you can choose from depending on your requirements.OAuth authenticationThis method will allow your application to make requests on behalf of any user who logs in.For this, specify your app's consumer key and secret:>>>d.set_consumer_key('key-here','secret-here')# Or you can do this when you instantiate the ClientThen go through the OAuth 1.0a process. In a web app, we'd specify acallback_url. In this example, we'll use the OOB flow.>>>d.get_authorize_url()('request-token','request-secret','authorize-url-here')The client will hang on to the access token and secret, but in a web app, you'd want to persist those and pass them into a newClientinstance on the next request.Next, visit the authorize URL, authenticate as a Discogs user, and get the verifier:>>>d.get_access_token('verifier-here')('access-token-here','access-secret-here')Now you can make requests on behalf of the user.>>>me=d.identity()>>>"I'm{0}({1}) from{2}.".format(me.name,me.username,me.location)u"I'm Joe Bloggs (example) from Portland, Oregon.">>>len(me.wantlist)3>>>me.wantlist.add(d.release(5))>>>len(me.wantlist)4User-token authenticationThis is one of the simplest ways to authenticate and become able to perform requests requiring authentication, such as search (see below). The downside is that you'll be limited to the information only your user account can see (i.e., no requests on behalf of other users).For this, you'll need to generate a user-token from your developer settings on the Discogs website.>>>d=discogs_api.Client('ExampleApplication/0.1',user_token="my_user_token")Fetching dataUse methods on the client to fetch objects. You can search for objects:>>>results=d.search('Stockholm By Night',type='release')>>>results.pages1>>>artist=results[0].artists[0]>>>artist.nameu'Persuader, The'Or fetch them by ID:>>>artist.id1>>>artist==d.artist(1)TrueYou can drill down as far as you like.>>>releases=d.search('Bit Shifter',type='artist')[0].releases[1].\...versions[0].labels[0].releases>>>len(releases)134ArtistQuery for an artist using the artist's name:>>>artist=d.artist(956139)>>>printartist<Artist"...">>>>'name'inartist.data.keys()TrueGet a list ofArtists representing this artist's aliases:>>>artist.aliases[...]Get a list ofReleases by this artist by page number:>>>artist.releases.page(1)[...]ReleaseQuery for a release using its Discogs ID:>>>release=d.release(221824)Get the title of thisRelease:>>>release.titleu'...'Get a list of allArtists associated with thisRelease:>>>release.artists[<Artist"...">]Get the tracklist for thisRelease:>>>release.tracklist[...]Get theMasterReleasefor thisRelease:>>>release.master<MasterRelease"...">Get a list of allLabels for thisRelease:>>>release.labels[...]MasterReleaseQuery for a master release using its Discogs ID:>>>master_release=d.master(120735)Get the keyReleasefor thisMasterRelease:>>>master_release.main_release<Release"...">Get the title of thisMasterRelease:>>>master_release.titleu'...'>>>master_release.title==master_release.main_release.titleTrueGet a list ofReleases representing other versions of thisMasterReleaseby page number:>>>master_release.versions.page(1)[...]Get the tracklist for thisMasterRelease:>>>master_release.tracklist[...]LabelQuery for a label using the label's name:>>>label=d.label(6170)Get a list ofReleases from thisLabelby page number:>>>label.releases.page(1)[...]Get a list ofLabels representing sublabels associated with thisLabel:>>>label.sublabels[...]Get theLabel's parent label, if it exists:>>>label.parent_label<Label"Warp Records Limited">