Client module¶
Implements a client class to query the Deezer API
- class deezer.client.Client(app_id=None, app_secret=None, access_token=None, headers=None, **kwargs)¶
A client to retrieve some basic infos about Deezer resourses.
Create a client instance with the provided options. Options should be passed in to the constructor as kwargs.
>>> import deezer >>> client = deezer.Client(app_id='foo', app_secret='bar')
This client provides several method to retrieve the content of most sort of Deezer objects, based on their json structure.
Headers can be forced by using the
headers
kwarg. For example, useAccept-Language
header to force the output language.>>> import deezer >>> client = deezer.Client(headers={'Accept-Language': 'fr'})
- Parameters
app_id – appliication ID.
app_secret – application secret.
access_token – user access token.
headers – a dictionary of headers to be used.
- add_user_album(album_id: int) bool ¶
Add an album to the user’s library
- Parameters
album_id – the ID of the album to add.
- Returns
boolean whether the operation succeeded.
- add_user_artist(artist_id: int) bool ¶
Add an artist to the user’s library
- Parameters
artist_id – the ID of the artist to add.
- Returns
boolean whether the operation succeeded.
- add_user_track(track_id: int) bool ¶
Add a track to the user’s library
- Parameters
track_id – the ID of the track to add.
- Returns
boolean whether the operation succeeded.
- advanced_search(terms, relation=None, index=0, limit=25, **kwargs)¶
Advanced search of track, album or artist.
See Search section of Deezer API for search terms.
- Returns
a list of
Resource
objects.
>>> client.advanced_search({"artist": "Daft Punk", "album": "Homework"}) >>> client.advanced_search( ... {"artist": "Daft Punk", "album": "Homework"}, ... relation="track", ... )
- get_album(object_id, relation=None, **kwargs)¶
Get the album with the provided ID.
- Returns
an
Album
object
- get_artist(object_id, relation=None, **kwargs)¶
Get the artist with the provided ID.
- Returns
an
Artist
object
- get_chart(relation=None, index=0, limit=10, **kwargs)¶
Get chart
- Returns
a list of
Resource
objects.
- get_object(object_t, object_id=None, relation=None, parent=None, **params)¶
Actually query the Deezer API to retrieve the object.
- Returns
an
Resource
or subclass.
- get_user_albums(user_id: Optional[int] = None) List[deezer.resources.Album] ¶
Get the favourites albums for the given user_id if provided or current user if not.
- Parameters
user_id – the user ID to get favourites albums.
- Returns
a list of
Album
instances.
- get_user_artists(user_id: Optional[int] = None) List[deezer.resources.Artist] ¶
Get the favourites artists for the given user_id if provided or current user if not.
- Parameters
user_id – the user ID to get favourites artists.
- Returns
a list of
Artist
instances.
- get_user_history() List[deezer.resources.Track] ¶
Returns a list of the recently played tracks for the current user.
- Returns
a list of
Track
instances.
- get_user_tracks(user_id: Optional[int] = None) List[deezer.resources.Track] ¶
Get the favourites tracks for the given user_id if provided or current user if not.
- Parameters
user_id – the user ID to get favourites tracks.
- Returns
a list of
Track
instances.
- object_url(object_t, object_id=None, relation=None)¶
Helper method to build the url to query to access the object passed as parameter
- Raises
TypeError – if the object type is invalid
- rate_album(album_id: str, note: int) bool ¶
Rate the album of the given ID with the given note.
The note should be and integer between 1 and 5.
- Returns
boolean whether rating was applied
- remove_user_album(album_id: int) bool ¶
Remove an album from the user’s library
- Parameters
album_id – the ID of the album to remove.
- Returns
boolean whether the operation succeeded.
- remove_user_artist(artist_id: int) bool ¶
Remove an artist from the user’s library
- Parameters
artist_id – the ID of the artist to remove.
- Returns
boolean whether the operation succeeded.
- remove_user_track(track_id: int) bool ¶
Remove a track from the user’s library
- Parameters
track_id – the ID of the track to remove.
- Returns
boolean whether the operation succeeded.
- request(method: str, path: str, **params)¶
Make a request to the API and parse the response.
- Parameters
method – HTTP verb to use: GET, POST< DELETE, …
path – The path to make the API call to (e.g. ‘artist/1234’)
params – Query parameters to add the the request
- Returns
- search(query, relation=None, index=0, limit=25, **kwargs)¶
Search track, album, artist or user
- Returns
a list of
Resource
objects.
- static url(request_path='')¶
Build the url with the appended request if provided.