API#

class minim.discogs.API(*, consumer_key: str = None, consumer_secret: str = None, flow: str = None, browser: bool = False, web_framework: str = None, port: int | str = 8888, redirect_uri: str = None, access_token: str = None, access_token_secret: str = None, overwrite: bool = False, save: bool = True)[source]#

Bases: object

Discogs API client.

The Discogs API lets developers build their own Discogs-powered applications for the web, desktop, and mobile devices. It is a RESTful interface to Discogs data and enables accessing JSON- formatted information about artists, releases, and labels, managing user collections and wantlists, creating marketplace listings, and more.

See also

For more information, see the Discogs API home page.

The Discogs API can be accessed with or without authentication. (client credentials, personal access token, or OAuth access token and access token secret). However, it is recommended that users at least provide client credentials to enjoy higher rate limits and access to image URLs. The consumer key and consumer secret can either be provided to this class’s constructor as keyword arguments or be stored as DISCOGS_CONSUMER_KEY and DISCOGS_CONSUMER_SECRET in the operating system’s environment variables.

See also

To get client credentials, see the Registration section of the Authentication page of the Discogs API website. To take advantage of Minim’s automatic access token retrieval functionality for the OAuth 1.0a flow, the redirect URI should be in the form http://localhost:{port}/callback, where {port} is an open port on localhost.

To view and make changes to account information and resources, users must either provide a personal access token to this class’s constructor as a keyword argument or undergo the OAuth 1.0a flow, which require valid client credentials, using Minim. If an existing OAuth access token/secret pair is available, it can be provided to this class’s constructor as keyword arguments to bypass the access token retrieval process.

Tip

The authorization flow and access token can be changed or updated at any time using set_flow() and set_access_token(), respectively.

Minim also stores and manages access tokens and their properties. When the OAuth 1.0a flow is used to acquire an access token/secret pair, it is automatically saved to the Minim configuration file to be loaded on the next instantiation of this class. This behavior can be disabled if there are any security concerns, like if the computer being used is a shared device.

Parameters:
consumer_keystr, keyword-only, optional

Consumer key. Required for the OAuth 1.0a flow, and can be used in the Discogs authorization flow alongside a consumer secret. If it is not stored as DISCOGS_CONSUMER_KEY in the operating system’s environment variables or found in the Minim configuration file, it can be provided here.

consumer_secretstr, keyword-only, optional

Consumer secret. Required for the OAuth 1.0a flow, and can be used in the Discogs authorization flow alongside a consumer key. If it is not stored as DISCOGS_CONSUMER_SECRET in the operating system’s environment variables or found in the Minim configuration file, it can be provided here.

flowstr, keyword-only, optional

Authorization flow. If None and no access token is provided, no user authentication will be performed and client credentials will not be attached to requests, even if found or provided.

Valid values:

  • None for no user authentication.

  • "discogs" for the Discogs authentication flow.

  • "oauth" for the OAuth 1.0a flow.

browserbool, keyword-only, default: False

Determines whether a web browser is automatically opened for the OAuth 1.0a flow. If False, users will have to manually open the authorization URL and provide the full callback URI via the terminal.

web_frameworkstr, keyword-only, optional

Determines which web framework to use for the OAuth 1.0a flow.

Valid values:

  • "http.server" for the built-in implementation of HTTP servers.

  • "flask" for the Flask framework.

  • "playwright" for the Playwright framework by Microsoft.

portint or str, keyword-only, default: 8888

Port on localhost to use for the OAuth 1.0a flow with the http.server and Flask frameworks. Only used if redirect_uri is not specified.

redirect_uristr, keyword-only, optional

Redirect URI for the OAuth 1.0a flow. If not on localhost, the automatic request access token retrieval functionality is not available.

access_tokenstr, keyword-only, optional

Personal or OAuth access token. If provided here or found in the Minim configuration file, the authentication process is bypassed.

access_token_secretstr, keyword-only, optional

OAuth access token secret accompanying access_token.

overwritebool, keyword-only, default: False

Determines whether to overwrite an existing access token in the Minim configuration file.

savebool, keyword-only, default: True

Determines whether newly obtained access tokens and their associated properties are stored to the Minim configuration file.

Attributes:
API_URLstr

Base URL for the Discogs API.

ACCESS_TOKEN_URLstr

URL for the OAuth 1.0a access token endpoint.

AUTH_URLstr

URL for the OAuth 1.0a authorization endpoint.

REQUEST_TOKEN_URLstr

URL for the OAuth 1.0a request token endpoint.

sessionrequests.Session

Session used to send requests to the Discogs API.

Methods

create_listing

delete_listing

delete_user_release_rating

Database > Release Rating By User > Delete Release Rating By User: Deletes the release's rating for a given user.

edit_listing

edit_order

edit_profile

User Identity > Profile > Edit Profile: Edit a user's profile data.

get_artist

Database > Artist: Get an artist.

get_artist_releases

Database > Artist Releases: Get an artist's releases and masters.

get_community_release_rating

Database > Community Release Rating: Retrieves the community release rating average and count.

get_identity

User Identity > Identity: Retrieve basic information about the authenticated user.

get_inventory

Marketplace > Inventory: Get a seller's inventory.

get_label

Database > Label: Get a label, company, recording studio, locxation, or other entity involved with artists and releases.

get_label_releases

Database > Label Releases: Get a list of releases associated with the label.

get_listing

get_master_release

Database > Master Release: Get a master release.

get_master_release_versions

Database > Master Release Versions: Retrieves a list of all releases that are versions of this master.

get_order

get_profile

User Identity > Profile > Get Profile: Retrieve a user by username.

get_release

Database > Release: Get a release (physical or digital object released by one or more artists).

get_release_stats

Database > Release Stats: Retrieves the release's "have" and "want" counts.

get_user_contributions

User Identity > User Contributions: Retrieve a user's contributions (releases, labels, artists) by username.

get_user_release_rating

Database > Release Rating By User > Get Release Rating By User: Retrieves the release's rating for a given user.

get_user_submissions

User Identity > User Submissions: Retrieve a user's submissions (edits made to releases, labels, and artists) by username.

search

Database > Search: Issue a search query to the Discogs database.

set_access_token

Set the Discogs API personal or OAuth access token (and secret).

set_flow

Set the authorization flow.

update_user_release_rating

Database > Release Rating By User > Update Release Rating By User: Updates the release's rating for a given user.

set_access_token(access_token: str = None, access_token_secret: str = None) None[source]#

Set the Discogs API personal or OAuth access token (and secret).

Parameters:
access_tokenstr, optional

Personal or OAuth access token.

access_token_secretstr, optional

OAuth access token secret.

set_flow(flow: str, *, consumer_key: str = None, consumer_secret: str = None, browser: bool = False, web_framework: str = None, port: int | str = 8888, redirect_uri: str = None, save: bool = True) None[source]#

Set the authorization flow.

Parameters:
flowstr

Authorization flow. If None, no user authentication will be performed and client credentials will not be attached to requests, even if found or provided.

Valid values:

  • None for no user authentication.

  • "discogs" for the Discogs authentication flow.

  • "oauth" for the OAuth 1.0a flow.

consumer_keystr, keyword-only, optional

Consumer key. Required for the OAuth 1.0a flow, and can be used in the Discogs authorization flow alongside a consumer secret. If it is not stored as DISCOGS_CONSUMER_KEY in the operating system’s environment variables or found in the Minim configuration file, it can be provided here.

consumer_secretstr, keyword-only, optional

Consumer secret. Required for the OAuth 1.0a flow, and can be used in the Discogs authorization flow alongside a consumer key. If it is not stored as DISCOGS_CONSUMER_SECRET in the operating system’s environment variables or found in the Minim configuration file, it can be provided here.

browserbool, keyword-only, default: False

Determines whether a web browser is automatically opened for the OAuth 1.0a flow. If False, users will have to manually open the authorization URL and provide the full callback URI via the terminal.

web_frameworkstr, keyword-only, optional

Determines which web framework to use for the OAuth 1.0a flow.

Valid values:

  • "http.server" for the built-in implementation of HTTP servers.

  • "flask" for the Flask framework.

  • "playwright" for the Playwright framework by Microsoft.

portint or str, keyword-only, default: 8888

Port on localhost to use for the OAuth 1.0a flow with the http.server and Flask frameworks. Only used if redirect_uri is not specified.

redirect_uristr, keyword-only, optional

Redirect URI for the OAuth 1.0a flow. If not on localhost, the automatic request access token retrieval functionality is not available.

savebool, keyword-only, default: True

Determines whether newly obtained access tokens and their associated properties are stored to the Minim configuration file.

get_release(release_id: int | str, *, curr_abbr: str = None) dict[str, Any][source]#

Database > Release: Get a release (physical or digital object released by one or more artists).

Parameters:
release_idint or str

The release ID.

Example: 249504.

curr_abbrstr, keyword-only, optional

Currency abbreviation for marketplace data. Defaults to the authenticated user’s currency.

Valid values: "USD", "GBP", "EUR", "CAD", "AUD", "JPY", "CHF", "MXN", "BRL", "NZD", "SEK", and "ZAR".

Returns:
releasedict

Discogs database information for a single release.

get_user_release_rating(release_id: int | str, username: str = None) dict[str, Any][source]#

Database > Release Rating By User > Get Release Rating By User: Retrieves the release’s rating for a given user.

Parameters:
release_idint or str

The release ID.

Example: 249504.

usernamestr, optional

The username of the user whose rating you are requesting. If not specified, the username of the authenticated user is used.

Example: "memory".

Returns:
ratingdict

Rating for the release by the given user.

update_user_release_rating(release_id: int | str, rating: int, username: str = None) dict[str, Any][source]#

Database > Release Rating By User > Update Release Rating By User: Updates the release’s rating for a given user.

User authentication

Requires user authentication with a personal access token or via the OAuth 1.0a flow.

Parameters:
release_idint or str

The release ID.

Example: 249504.

ratingint

The new rating for a release between \(1\) and \(5\).

usernamestr, optional

The username of the user whose rating you are requesting. If not specified, the username of the authenticated user is used.

Example: "memory".

Returns:
ratingdict

Updated rating for the release by the given user.

delete_user_release_rating(release_id: int | str, username: str = None) None[source]#

Database > Release Rating By User > Delete Release Rating By User: Deletes the release’s rating for a given user.

User authentication

Requires user authentication with a personal access token or via the OAuth 1.0a flow.

Parameters:
release_idint or str

The release ID.

Example: 249504.

usernamestr, optional

The username of the user whose rating you are requesting. If not specified, the username of the authenticated user is used.

Example: "memory".

get_community_release_rating(release_id: int | str) dict[str, Any][source]#

Database > Community Release Rating: Retrieves the community release rating average and count.

Parameters:
release_idint or str

The release ID.

Example: 249504.

Returns:
ratingdict

Community release rating average and count.

get_release_stats(release_id: int | str) dict[str, Any][source]#

Database > Release Stats: Retrieves the release’s “have” and “want” counts.

Attention

This endpoint does not appear to be working correctly. Currently, the response will be of the form

{
  "is_offense": <bool>
}
Parameters:
release_idint or str

The release ID.

Example: 249504.

Returns:
statsdict

Release “have” and “want” counts.

get_master_release(master_id: int | str) dict[str, Any][source]#

Database > Master Release: Get a master release.

Parameters:
master_idint or str

The master release ID.

Example: 1000.

Returns:
master_releasedict

Discogs database information for a single master release.

get_master_release_versions(master_id: int | str, *, country: str = None, format: str = None, label: str = None, released: str = None, page: int = None, per_page: int = None, sort: str = None, sort_order: str = None) dict[str, Any][source]#

Database > Master Release Versions: Retrieves a list of all releases that are versions of this master.

Parameters:
master_idint or str

The master release ID.

Example: 1000.

countrystr, keyword-only, optional

The country to filter for.

Example: "Belgium".

formatstr, keyword-only, optional

The format to filter for.

Example: "Vinyl".

labelstr, keyword-only, optional

The label to filter for.

Example: "Scorpio Music".

releasedstr, keyword-only, optional

The release year to filter for.

Example: "1992".

pageint, keyword-only, optional

The page you want to request.

Example: 3.

per_pageint, keyword-only, optional

The number of items per page.

Example: 25.

sortstr, keyword-only, optional

Sort items by this field.

Valid values: "released", "title", "format", "label", "catno", and "country".

sort_orderstr, keyword-only, optional

Sort items in a particular order.

Valid values: "asc" and "desc".

Returns:
versionsdict

Discogs database information for all releases that are versions of the specified master.

get_artist(artist_id: int | str) dict[str, Any][source]#

Database > Artist: Get an artist.

Parameters:
artist_idint or str

The artist ID.

Example: 108713.

Returns:
artistdict

Discogs database information for a single artist.

get_artist_releases(artist_id: int | str, *, page: int = None, per_page: int = None, sort: str = None, sort_order: str = None) dict[str, Any][source]#

Database > Artist Releases: Get an artist’s releases and masters.

Parameters:
artist_idint or str

The artist ID.

Example: 108713.

pageint, keyword-only, optional

Page of results to fetch.

per_pageint, keyword-only, optional

Number of results per page.

sortstr, keyword-only, optional

Sort results by this field.

Valid values: "year", "title", and "format".

sort_orderstr, keyword-only, optional

Sort results in a particular order.

Valid values: "asc" and "desc".

Returns:
releasesdict

Discogs database information for all releases by the specified artist.

get_label(label_id: int | str) dict[str, Any][source]#

Database > Label: Get a label, company, recording studio, locxation, or other entity involved with artists and releases.

Parameters:
label_idint or str

The label ID.

Example: 1.

Returns:
labeldict

Discogs database information for a single label.

get_label_releases(label_id: int | str, *, page: int = None, per_page: int = None) dict[str, Any][source]#

Database > Label Releases: Get a list of releases associated with the label.

Parameters:
label_idint or str

The label ID.

Example: 1.

pageint, keyword-only, optional

Page of results to fetch.

per_pageint, keyword-only, optional

Number of results per page.

Returns:
releasesdict

Discogs database information for all releases by the specified label.

search(query: str = None, *, type: str = None, title: str = None, release_title: str = None, credit: str = None, artist: str = None, anv: str = None, label: str = None, genre: str = None, style: str = None, country: str = None, year: str = None, format: str = None, catno: str = None, barcode: str = None, track: str = None, submitter: str = None, contributor: str = None) dict[str, Any][source]#

Database > Search: Issue a search query to the Discogs database.

Authentication

Requires authentication with consumer credentials, with a personal access token, or via the OAuth 1.0a flow.

Parameters:
querystr, optional

The search query.

Example: "Nirvana".

typestr, keyword-only, optional

The type of item to search for.

Valid values: "release", "master", "artist", and "label".

titlestr, keyword-only, optional

Search by combined "<artist name> - <release title>" title field.

Example: "Nirvana - Nevermind".

release_titlestr, keyword-only, optional

Search release titles.

Example: "Nevermind".

creditstr, keyword-only, optional

Search release credits.

Example: "Kurt".

artiststr, keyword-only, optional

Search artist names.

Example: "Nirvana".

anvstr, keyword-only, optional

Search artist name variations (ANV).

Example: "Nirvana".

labelstr, keyword-only, optional

Search labels.

Example: "DGC".

genrestr, keyword-only, optional

Search genres.

Example: "Rock".

stylestr, keyword-only, optional

Search styles.

Example: "Grunge".

countrystr, keyword-only, optional

Search release country.

Example: "Canada".

yearstr, keyword-only, optional

Search release year.

Example: "1991".

formatstr, keyword-only, optional

Search formats.

Example: "Album".

catnostr, keyword-only, optional

Search catalog number.

Example: "DGCD-24425".

barcodestr, keyword-only, optional

Search barcode.

Example: "720642442524".

trackstr, keyword-only, optional

Search track.

Example: "Smells Like Teen Spirit".

submitterstr, keyword-only, optional

Search submitter username.

Example: "milKt".

contributorstr, keyword-only, optional

Search contributor username.

Example: "jerome99".

Returns:
resultsdict

Search results.

get_inventory(username: str, *, status: str = None, page: str = None, per_page: str = None, sort: str = None, sort_order: str = None) dict[str, Any][source]#

Marketplace > Inventory: Get a seller’s inventory.

Parameters:
usernamestr

The username of the inventory owner.

Example: "360vinyl".

statusstr, keyword-only, optional

The status of the listings to return.

Valid values: "For Sale", "Draft", "Expired", "Sold", and "Deleted".

pagestr, keyword-only, optional

The page you want to request.

Example: 3.

per_pagestr, keyword-only, optional

The number of items per page.

Example: 25.

sortstr, keyword-only, optional

Sort items by this field.

Valid values: "listed", "price", "item", "artist", "label", "catno", "audio", "status", and "location".

sort_orderstr, keyword-only, optional

Sort items in a particular order.

Valid values: "asc" and "desc".

Returns:
inventorydict

The seller’s inventory.

get_identity() dict[str, Any][source]#

User Identity > Identity: Retrieve basic information about the authenticated user.

User authentication

Requires user authentication with a personal access token or via the OAuth 1.0a flow.

You can use this resource to find out who you’re authenticated as, and it also doubles as a good sanity check to ensure that you’re using OAuth correctly.

For more detailed information, make another request for the user’s profile using get_profile().

Returns:
identitydict

Basic information about the authenticated user.

get_profile(username: str = None) dict[str, Any][source]#

User Identity > Profile > Get Profile: Retrieve a user by username.

If authenticated as the requested user, the "email" key will be visible, and the "num_lists" count will include the user’s private lists.

If authenticated as the requested user or the user’s collection/wantlist is public, the "num_collection"/"num_wantlist" keys will be visible.

Parameters:
usernamestr, optional

The username of whose profile you are requesting. If not specified, the username of the authenticated user is used.

Example: "rodneyfool".

Returns:
profiledict

Detailed information about the user.

edit_profile(*, name: str = None, home_page: str = None, location: str = None, profile: str = None, curr_abbr: str = None) dict[str, Any][source]#

User Identity > Profile > Edit Profile: Edit a user’s profile data.

User authentication

Requires user authentication with a personal access token or via the OAuth 1.0a flow.

Parameters:
namestr, keyword-only, optional

The real name of the user.

Example: "Nicolas Cage".

home_pagestr, keyword-only, optional

The user’s website.

Example: "www.discogs.com".

locationstr, keyword-only, optional

The geographical location of the user.

Example: "Portland".

profilestr, keyword-only, optional

Biological information about the user.

Example: "I am a Discogs user!".

curr_abbrstr, keyword-only, optional

Currency abbreviation for marketplace data.

Valid values: "USD", "GBP", "EUR", "CAD", "AUD", "JPY", "CHF", "MXN", "BRL", "NZD", "SEK", and "ZAR".

Returns:
profiledict

Updated profile.

get_user_submissions(username: str = None, *, page: int = None, per_page: int = None) dict[str, Any][source]#

User Identity > User Submissions: Retrieve a user’s submissions (edits made to releases, labels, and artists) by username.

Parameters:
usernamestr, optional

The username of the submissions you are trying to fetch. If not specified, the username of the authenticated user is used.

Example: "shooezgirl".

pageint, keyword-only, optional

Page of results to fetch.

per_pageint, keyword-only, optional

Number of results per page.

Returns:
submissionsdict

Submissions made by the user.

get_user_contributions(username: str = None, *, page: int = None, per_page: int = None, sort: str = None, sort_order: str = None) dict[str, Any][source]#

User Identity > User Contributions: Retrieve a user’s contributions (releases, labels, artists) by username.

Parameters:
usernamestr, optional

The username of the contributions you are trying to fetch. If not specified, the username of the authenticated user is used.

Example: "shooezgirl".

pageint, keyword-only, optional

Page of results to fetch.

per_pageint, keyword-only, optional

Number of results per page.

sortstr, keyword-only, optional

Sort items by this field.

Valid values: "label", "artist", "title", "catno", "format", "rating", "year", and "added".

sort_orderstr, keyword-only, optional

Sort items in a particular order.

Valid values: "asc" and "desc".

Returns:
contributionsdict

Contributions made by the user.