Python interface to the Discogs REST API
Project description
Discogs API Client
This is a Python interface to the Discogs REST API. It is intended as a drop-in replacement for the now deprecated discogs-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.
Installation
Install the client from PyPI using your favorite package manager.
pip install discogs_api
Quickstart
Instantiating the client object
>>> import discogs_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 authentication
This 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 Client
Then go through the OAuth 1.0a process. In a web app, we'd specify a callback_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 new Client
instance 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)
4
User-token authentication
This 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 data
Use methods on the client to fetch objects. You can search for objects:
>>> results = d.search('Stockholm By Night', type='release')
>>> results.pages
1
>>> artist = results[0].artists[0]
>>> artist.name
u'Persuader, The'
Or fetch them by ID:
>>> artist.id
1
>>> artist == d.artist(1)
True
You 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)
134
Artist
Query for an artist using the artist's name:
>>> artist = d.artist(956139)
>>> print artist
<Artist "...">
>>> 'name' in artist.data.keys()
True
Get a list of Artist
s representing this artist's aliases:
>>> artist.aliases
[...]
Get a list of Release
s by this artist by page number:
>>> artist.releases.page(1)
[...]
Release
Query for a release using its Discogs ID:
>>> release = d.release(221824)
Get the title of this Release
:
>>> release.title
u'...'
Get a list of all Artist
s associated with this Release
:
>>> release.artists
[<Artist "...">]
Get the tracklist for this Release
:
>>> release.tracklist
[...]
Get the MasterRelease
for this Release
:
>>> release.master
<MasterRelease "...">
Get a list of all Label
s for this Release
:
>>> release.labels
[...]
MasterRelease
Query for a master release using its Discogs ID:
>>> master_release = d.master(120735)
Get the key Release
for this MasterRelease
:
>>> master_release.main_release
<Release "...">
Get the title of this MasterRelease
:
>>> master_release.title
u'...'
>>> master_release.title == master_release.main_release.title
True
Get a list of Release
s representing other versions of this MasterRelease
by page number:
>>> master_release.versions.page(1)
[...]
Get the tracklist for this MasterRelease
:
>>> master_release.tracklist
[...]
Label
Query for a label using the label's name:
>>> label = d.label(6170)
Get a list of Release
s from this Label
by page number:
>>> label.releases.page(1)
[...]
Get a list of Label
s representing sublabels associated with this Label
:
>>> label.sublabels
[...]
Get the Label
's parent label, if it exists:
>>> label.parent_label
<Label "Warp Records Limited">
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file discogs-api-0.1.0.tar.gz
.
File metadata
- Download URL: discogs-api-0.1.0.tar.gz
- Upload date:
- Size: 35.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a56ae14f94bfb0ed63f5d5fa434dd9b72ab5689453ee4456c8ab526198334fe3 |
|
MD5 | 8fe99c14d8a94e7bf7aaf098dd8dc0ff |
|
BLAKE2b-256 | e839d35d4c41d5802860c6c239a523deb7f0fa7d3b409ea1d4b0f98e6b488a15 |
File details
Details for the file discogs_api-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: discogs_api-0.1.0-py3-none-any.whl
- Upload date:
- Size: 22.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 85ff62bf6c3e9cf0547e7e851824040682402f016d4bf7c7eb462226c734e4e1 |
|
MD5 | 6aa7dae30b2630aaf88ebae25532b17f |
|
BLAKE2b-256 | f739eae859334e0017b66ce98935703a04e87db5eacc9cae347a9b8a04bea5c4 |