Deezer’s API with python

This article will show you how to use Deezer’s API with python and Flask. We will create a project, see how to authenticate to the API, use some route to retrieves information and play music with the plugin.


  • You need a Deezer account
  • Go to and create an a new app. You can set in Redirect URL field.
  • You will need your Application ID, Secret Key and the Redirect URL to use the API

Set up project

  1. Create your project
  2. Create your virtual env
  3. Install packages
pip install Flask
pip install request

4. Add an file. Add the code below in it, and fill your information in the three variables.

from flask import Flask

app = Flask(__name__)


def default():

if __name__ == '__main__':

Your project is now ready.


You can find the documentation here:

We will create two routes for the authentification.

The first one will open a popup if the user is not connected. And you will be redirected to your DEEZER_REDIRECT_URI with an authorization code in the parameters.

@app.route('/', methods=['GET'])
def default():
url = (f'{DEEZER_APP_ID}'
return redirect(url)

The second one will request the access token thanks to the authorization code.

# This path should be your redirect url
@app.route('/deezer/login', methods=['GET'])
def deezer_login():
# retrieve the authorization code given in the url
code = request.args.get('code')

# request the access token
url = (f'{DEEZER_APP_ID}'
response = requests.get(url)

# If it's not a good code we will get this error
if response.text == 'wrong code':
return 'wrong code'

# We have our access token
response = response.json()
return response['access_token']

Start your API with : python

Go to A page will open and let you login with your Deezer account. On the next page, your app will ask for permissions. And after accepting, you will end up on your redirect page, with your access token displayed on it.

Use the API and play music

We will go through an example of the use of the API. It will be pretty much the same for each other routes. You can find all in the documentation.

This route, will retrieve all your playlists and give you a json will all the information (id, title, description, list of tracks …)

@app.route('/playlists', methods=['GET'])
def get_playlists():
access_token = request.args.get('token')

response = requests.get(f'', {'access_token': access_token})
return response.json()

Keep an ID of one your playlists, we will play it in the next route.

To play music, we have to use the Deezer's plugins. We can customize it here. It’s just an url that you embed in an iframe (or something similar). Our route will take in parameters, the “type_” of content you want to play (can be “playlist”, “album”, “tracks”, “charts” or “favourites”) and the corresponding “id_”.

@app.route('/play', methods=['GET'])
def play():
id_ = request.args.get('id_')
type_ = request.args.get('type_')

url = (f''

return redirect(url)

For example will play your playlist

One of my playlists

NB: This is now the best ways and most secure ways of creating an API, and to pass an access token. But for a personal project it will do the job

If you are interested I made a python package (deezersdk) to wrap the API.

Thanks for reading this article. Please let me some comments to improve my future articles, my English, my code or just to say hi.

I work at yper. I’m a python developper, learning data-science. I’ve made a app. You can buy me coffee :

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store