DEPRECATED - Official Python Client for the Discogs API

Overview

⚠️ DEPRECATED

This repository is no longer maintained. You can still use a REST client like Requests or other third-party Python library to access the Discogs REST API.




Discogs API Client

This is the official Discogs API client for Python. 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.

Build Status Coverage Status

Installation

Install the client from PyPI using your favorite package manager.

$ pip install discogs_client

Quickstart

Instantiating the client object

>>> import discogs_client
>>> d = discogs_client.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_client.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

Special properties

Get a list of Artists representing this artist's aliases:

>>> artist.aliases
[...]

Get a list of Releases by this artist by page number:

>>> artist.releases.page(1)
[...]

Release

Query for a release using its Discogs ID:

>>> release = d.release(221824)

Special properties

Get the title of this Release:

>>> release.title
u'...'

Get a list of all Artists 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 Labels for this Release:

>>> release.labels
[...]

MasterRelease

Query for a master release using its Discogs ID:

>>> master_release = d.master(120735)

Special properties

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 Releases 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)

Special properties

Get a list of Releases from this Label by page number:

>>> label.releases.page(1)
[...]

Get a list of Labels representing sublabels associated with this Label:

>>> label.sublabels
[...]

Get the Label's parent label, if it exists:

>>> label.parent_label
<Label "Warp Records Limited">

Contributing

  1. Fork this repo
  2. Create a feature branch
  3. Open a pull-request

For more information

Check the included documentation, or just spin up a REPL and use dir() on things :)

Comments
  • Make discogs_client python 2 & python 3 compatible

    Make discogs_client python 2 & python 3 compatible

    This PR makes discogs_client python 2 and python 3 compatible.

    Notables changes include:

    • switch from python-oauth2 (no py3k compatibility) to oauthlib (β†’ helps with #40)
    • fix numerous pep8 error
    • make tests deterministic
    opened by brunal 20
  • Add user token authentication

    Add user token authentication

    I've just added user_token "authentication".

    Can't figure out how to add a test for it, but you can use this for testing:

    __author__ = 'aweil'
    import os
    import unittest
    import discogs_client
    
    class UserTokenTest(unittest.TestCase):
        def setUp(self):
            with open(os.path.expanduser('~/.discogs_user_token'), 'rb') as f:
                self.discosgs_token = f.read().strip()
    
        def test_search(self):
            d = discogs_client.Client('TenukiWebApp1/0.1', user_token=self.discosgs_token)
            query_releases = d.search('Bit Shifter', type='artist')[0].releases[1].versions[0].labels[0].releases
            self.assertTrue( len(query_releases)>0)
    
    if __name__ == '__main__':
        unittest.main()
    

    Please let me know when/where to add documentation when available and if you want I to documentate it in the readme.

    opened by tenuki 10
  • Detailed exceptions for token request failures

    Detailed exceptions for token request failures

    This adds richer exception information when the request token request fails. This is important because it can fail for several different reasons, including:

    • bad timestamp
    • bad consumer
    • bad signature

    This makes it at least possible to tell what's going wrong.

    Before:

    $ python -c "import discogs_client ; discogs_client.Client('[...]', '[...]', '[...]').get_authorize_url()"
    [...]
    discogs_client.exceptions.HTTPError: 401: Invalid response from request token URL.
    

    After:

    $ python -c "import discogs_client ; discogs_client.Client('[...]', '[...]', '[...]').get_authorize_url()"
    [...]
    discogs_client.exceptions.AuthorizationError: 401: Could not get request token. Response: 'Invalid consumer.'
    

    This came up in https://github.com/sampsyo/beets/issues/1417.

    opened by sampsyo 9
  • discogs_client doesnt honor Discogs rate limits

    discogs_client doesnt honor Discogs rate limits

    Discogs has recently lowered their rate limit from 240 reqs/min to 60 reqs/min. This obviously means that some applications will hit the limit quite soon.

    opened by T-101 8
  • Checkout fails on Windows due to invalid file names

    Checkout fails on Windows due to invalid file names

    Git checkout of repository fails.... error: unable to create file discogs_client/tests/res/artists/1/releases?per_page=50&page=1.json (Invalid argument) error: unable to create file discogs_client/tests/res/artists/1/releases?per_page=50&page=2.json (Invalid argument) error: unable to create file discogs_client/tests/res/database/search?q=trash80&per_page=50&page=1.json (Invalid argument) error: unable to create file discogs_client/tests/res/masters/4242/versions?per_page=50&page=1.json (Invalid argument) error: unable to create file discogs_client/tests/res/users/example/wants?per_page=50&page=1.json (Invalid argument)

    opened by zoomorph 8
  • requests.get has wrong parameters

    requests.get has wrong parameters

    With the current git clone (but I think this was also present with the version coming from pypi) I get the following traceback:

    >>> r = discogs.Release( 934425 )
    >>> t = r.tracklist[9]
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/local/lib/python2.7/dist-packages/discogs_client-1.1.0-py2.7.egg/discogs_client.py", line 165, in tracklist
        for track in self.data.get('tracklist', []):
      File "/usr/local/lib/python2.7/dist-packages/discogs_client-1.1.0-py2.7.egg/discogs_client.py", line 52, in data
        if self._response.content and self._response.status_code == 200:
      File "/usr/local/lib/python2.7/dist-packages/discogs_client-1.1.0-py2.7.egg/discogs_client.py", line 38, in _response
        self._cached_response = requests.get(self._uri, self._params, self._headers)
    TypeError: get() takes exactly 1 argument (3 given)
    

    during the install (python setup.py install) it installed version 0.6.1 of the python-requests library.

    I was doing a fork but right now git push doesn't seem to be working, so here is just the trivial patch as plain text:

    diff --git a/discogs_client.py b/discogs_client.py
    index f52d769..ee2e48d 100644
    --- a/discogs_client.py
    +++ b/discogs_client.py
    @@ -35,7 +35,7 @@ class APIBase(object):
             if not self._cached_response:
                 if not self._check_user_agent():
                     raise DiscogsAPIError, 'Invalid or no User-Agent set'
    -            self._cached_response = requests.get(self._uri, self._params, self._headers)
    +            self._cached_response = requests.get(self._uri, params=self._params, headers=self._headers)
     
             return self._cached_response
    
    
    opened by matigit 7
  • TypeError: __repr__ returned non-string (type bytes)

    TypeError: __repr__ returned non-string (type bytes)

    Here is a minimal example of my attempts to interact with the Discogs API:

    from SensitiveInformation.discogs_application_info import provide_discogs_auth, provide_verifier
    import discogs_client
    
    discogs_consumer_key, discogs_consumer_secret = provide_discogs_auth()
    discogs = discogs_client.Client(user_agent="ThoughfulMachineLearning",
                                    consumer_key=discogs_consumer_key,
                              consumer_secret=discogs_consumer_secret)
    discogs_auth_url = discogs.get_authorize_url()
    discogs.get_access_token(verifier=provide_verifier())
    discogs.identity()
    

    The functions provide_discogs_auth and provide_verifier simply return the consumer key & secret and the verifier from user authorization. get_access_token returns the access key and secret as expected.

    However, on the last line, when I make an API call, I get:

    Out[38]: In[39]: discogs.identity()
    Traceback (most recent call last):
    Out[39]:   File "/usr/local/lib/python3.4/dist-packages/IPython/core/formatters.py", line 219, in catch_format_error
        r = method(self, *args, **kwargs)
      File "/usr/local/lib/python3.4/dist-packages/IPython/core/formatters.py", line 690, in __call__
        printer.pretty(obj)
      File "/usr/local/lib/python3.4/dist-packages/IPython/lib/pretty.py", line 407, in pretty
        return _default_pprint(obj, self, cycle)
      File "/usr/local/lib/python3.4/dist-packages/IPython/lib/pretty.py", line 527, in _default_pprint
        _repr_pprint(obj, p, cycle)
      File "/usr/local/lib/python3.4/dist-packages/IPython/lib/pretty.py", line 709, in _repr_pprint
        output = repr(obj)
    TypeError: __repr__ returned non-string (type bytes)
    

    Not sure if this is related to IPython or the client library, but would appreciate help either way. Thanks.

    opened by tchakravarty 6
  • Fix Issue #37

    Fix Issue #37

    Fix Issue #37 -- allow to clone properly on Windows.

    • Renamed all test files to replace '?' with '_'
    • Changed FileSystemFetcher to likewise replace '?' with '_' when loading a test file
    • Added logic to FileSystemFetcher to check for all permutations of parameters contained in a test file's name.
    • Removed symlinks from repo.
    • The repo now clones cleanly on Windows.
    • Unit tests passed.
    opened by leo-dor 6
  • Non-ASCII searches fail because python-oauth2 is broken

    Non-ASCII searches fail because python-oauth2 is broken

    Searching for a non-ASCII term causes this error:

    >>> import discogs_client
    >>> c = discogs_client.Client('user_agent', 'bogus_key', 'bogus_secret')
    >>> c.search(u'caf\xe9'.encode('utf8')).page(1)
    Traceback (most recent call last):
    [ ... snip ... ]
      File "/usr/local/lib/python2.7/site-packages/oauth2/__init__.py", line 442, in to_url
        urllib.urlencode(query, True), fragment)
      File "/usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 1357, in urlencode
        l.append(k + '=' + quote_plus(str(elt)))
    UnicodeEncodeError: 'ascii' codec can't encode characters in position 3-4: ordinal not in range(128)
    

    This is due to a known bug in python-oauth2: https://github.com/simplegeo/python-oauth2/issues/154. That library, unfortunately, appears to be abandoned: the last commit was in 2011 (c.f. this lament over the sorry state of Python OAuth libraries).

    It's worth noting that this was not an issue when sending non-ASCII requests without OAuth authentication because they don't go through the broken library. This has only come up recently because the search API now requires authentication, so we're now these previously-working requests are now hitting this bug.

    As unattractive as it seems, I think the only solution may be to move to a more modern OAuth library. Personally, I've had success with rauth.

    opened by sampsyo 6
  • Release attributes return different values depending on previosly accessed fiels

    Release attributes return different values depending on previosly accessed fiels

    from discogs_client import Client, Release
    
    
    client = Client('python')
    releases = [i for i in client.search('Flying Horseman') if isinstance(i, Release)]
    
    r = releases[3]
    print r.title           # Flying Horseman - City Same City
    print r.data['title']   # Flying Horseman - City Same City
    print r.master.title    # City Same City
    print r.title           # City Same City
    

    This behavior is really strange: Accessing Release.master.title also changes Release.title. I can't find a way to get just album name without artist, it works only if I access master first.

    opened by andriykohut 6
  • incorrect tracklist for versions with more than one side CD

    incorrect tracklist for versions with more than one side CD

    let us say i want to get a tracklist of this version of a release - https://www.discogs.com/Edward-Ka-Spel-Dream-Logik-Part-Two/master/277838 - works fine because it has only one side

    but

    let us say i want to get a tracklist of this version of a release which is double side LTD - https://www.discogs.com/Edward-Ka-Spel-Dream-Logik-Part-Two/release/1425757

    it returns a buggy list with two more strings which ARE NOT TRACKS but names of each side.

    opened by ExperimentalHypothesis 5
Releases(v2.3.0)
A simple Discord Mass Dm with Scraper

Python-Mass-DM A simple Discord Mass Dm with Scraper If Member Scraper in Taliban.py doesn't work. You can DM me cuz that scraper is for tokens that g

RyanzSantos 4 Sep 02, 2022
Your custom slash commands Discord bot!

Slashy - Your custom slash-commands bot Hey, I'm Slashy - your friendly neighborhood custom-command bot! The code for this bot exists because I'm like

Omar Zunic 8 Dec 20, 2022
Lamblayer: a minimal deployment tool for AWS Lambda layers

lamblayer lamblayer is a minimal deployment tool for AWS Lambda layers. lamblayer does, Create a Layers of built pip-installable python packages. Crea

Yusuke Takahashi 2 Aug 19, 2022
Python Library for Secp256k1 Bitcoin curve to do fast ECC calculation

secp256k1 Python Library for Secp256k1 Bitcoin curve to do fast ECC calculation Example Usage import secp256k1 as ice print('[C]',privatekey_to_addres

iceland 49 Jan 01, 2023
Automatically changes your discord status

Automatically changes your discord status, Be careful as this may get you rate limited and banned

octo 5 Sep 20, 2022
Uploader-Bot - A Modified Telegram Url Uploader Bot With Mongodb, Zee5, Sonyliv Support and Many Other Yt-dlp Sites

πšπšŽπššπšžπš’πš›πšŽπš πš…πšŠπš›πš’πšŠπš‹πš•πšŽπšœ πŸ”Š APP_ID API_HASH TG_BOT_TOKEN DATABASE_URL

11 Sep 10, 2022
Opasium AI was specifically designed for the Opasium Games discord only. It is a bot that covers the basic functions of any other bot.

OpasiumAI Opasium AI was specifically designed for the Opasium Games discord only. It is a bot that covers the basic functions of any other bot. Insta

Dan 3 Oct 15, 2021
Multipurpose Discord bot hosted on replit.com

RockyBot Multipurpose Discord bot hosted on https://replit.com/ Installing Dependencies Install poetry through pip: pip install poetry Then simply exe

Rocky 2 May 18, 2022
A Telegram Bot written in Python for mirroring files on the Internet to Google Drive

No support is going to be provided of any kind, only maintaining this for vps user on request. This is a Telegram Bot written in Python for mirroring

0 Dec 26, 2021
Use an air-gapped Raspberry Pi Zero to sign for Bitcoin transactions! (and do other cool stuff)

Hello World! Build your own offline, airgapped Bitcoin transaction signing device for less than $35! Also generate seed word 24 or generate a seed phr

371 Dec 31, 2022
Fastest Pancakeswap Sniper BOT TORNADO CASH 2022-V1 (MAC WINDOWS ANDROID LINUX)

Fastest Pancakeswap Sniper BOT TORNADO CASH 2022-V1 (MAC WINDOWS ANDROID LINUX) ⭐️ AUTO BUY TOKEN ON LAUNCH AFTER ADD LIQUIDITY ⭐️ ⭐️ Support Uniswap

Crypto Trader 7 Jan 31, 2022
PRAW, an acronym for "Python Reddit API Wrapper", is a python package that allows for simple access to Reddit's API.

PRAW: The Python Reddit API Wrapper PRAW, an acronym for "Python Reddit API Wrapper", is a Python package that allows for simple access to Reddit's AP

Python Reddit API Wrapper Development 3k Dec 29, 2022
Bot simply search for the files from provided channel according to given query and gives link to those files as buttons!

Auto Filter Bot γ…€γ…€γ…€γ…€γ…€γ…€γ…€ γ…€γ…€γ…€γ…€γ…€γ…€γ…€ You can call this as an Auto Filter Bot if you like :D Bot simply search for the files from provided channel according

TroJanzHEX 89 Nov 23, 2022
Handles SDVX EXCEED GEAR result screen photos and attempts to read it.

Handles SDVX EXCEED GEAR result screen photos and attempts to read it.

silverhawke 1 Jan 08, 2022
Discord bots that update their status to the price of any coin listed on x.vite.net

Discord bots that update their status to the price of any coin listed on x.vite.net

5am 3 Nov 27, 2022
Bot Maker For Discord - Python Edition

BMFD-PE Bot Maker For Discord - Python Edition BMFD-PE is a new version of BMFD write in Python The Version of BMFD-PE is : alpha0.1 Longer support :

TΓ©o 2 Dec 22, 2021
Ghost-toolbox - Ghost's official Discord raid tool

Ghost Toolbox Ghost's official Discord raid tool. How to use Clone this repo int

G H Ø S T 10 Oct 31, 2022
A simple bot that lives in your Telegram group, logging messages to a Postgresql database and serving statistical tables and plots to users as Telegram messages.

telegram-stats-bot Telegram-stats-bot is a simple bot that lives in your Telegram group, logging messages to a Postgresql database and serving statist

22 Dec 26, 2022
(unofficial) Googletrans: Free and Unlimited Google translate API for Python. Translates totally free of charge.

Googletrans Googletrans is a free and unlimited python library that implemented Google Translate API. This uses the Google Translate Ajax API to make

Suhun Han 3.2k Jan 04, 2023
GitHub action to deploy serverless functions to YandexCloud

YandexCloud serverless function deploy action Deploy new serverless function version (including function creation if it does not exist). Inputs yc_acc

Много Лосося 4 Apr 10, 2022