Skip to content

A light weight Python library for the Spotify Web API

License

Notifications You must be signed in to change notification settings

davidt99/spotipy

 
 

Repository files navigation

Spotipy - a Python client for The Spotify Web API

Description

Spotipy is a thin client library for the Spotify Web API. This fork is not compatible with the original spotipy library, see the difference section

Installation

If you already have Python on your system you can install the library simply by downloading the distribution, unpack it and install in the usual fashion:

python setup.py install

You can also install it using a popular package manager with

pip install git+https://github.com/davidt99/spotipy

or

easy_install spotipy

Dependencies

  • Python 3.5 and above, python 2.7 is not supported
  • Requests - spotipy requires the requests package to be installed

Development status

The library is still in beta, there are few things to do (feel free to open PR):

  • Rewrite the browse and library APIs
  • Add unit tests to client
  • Add integration tests to the authentication module
  • Rewrite the examples directory
  • Setup documentation

Authentication

The library provides 3 ways to authenticate:

  1. Using client id and client secret according to Client Credential method. This method is best suite when you don't need any user information or user related actions (like play/pause):
import spotipy.auth
auth_provider = spotipy.auth.ClientCredentials(client_id, client_secret)
  1. Using refresh token and client id and client secret according to Authorization Code. This method is best suite when you need to access user information and perform user related actions (like play/pause)
import spotipy.auth
auth_provider = spotipy.auth.AuthorizationCode(
    client_id, client_secret, refresh_token, persist_file_path="~/.spotify-cache"
)

In this example, the required parameters to authenticate again is stored in "~/.spotify-cache to allow loading the AuthorizationCode from a file:

import spotipy.auth
auth_provider = spotipy.auth.AuthorizationCode.load("~/.spotify-cache")

A helper method exists to help getting the refresh token:

import spotipy.util
auth_provider = spotipy.util.prompt_user_for_authorization_code_provider(
    client_id,
    client_secret,
    scope="user-read-playback-state user-modify-playback-state",
    persist_file_path="~/.spotify-cache",
    deploy_local_server=True,
)
  1. Simple access token, good for testing
import spotipy.auth
auth_provider = spotipy.auth.PlainAccessToken(access_token)

Quick Start

To get started, simply install spotipy, create a Spotify object and call methods:

import spotipy
import spotipy.auth
auth_provider = spotipy.auth.AuthorizationCode.load("~/.spotify-cache")
sp = spotipy.Spotify(auth_provider)

results = sp.search("weezer", "track",)
for track in results["tracks"]["items"]:
    print(track["name"])

Difference Between plamere/spotipy

This repository was forked form plamere/spotipy since it was no longer maintained.

There are few key differences:

  • Python 2.7 is not supported
  • The authenticate module was rewritten, see the Authentication section
  • Use the default values that the spotify API uses like limit and offset

Most of the client methods stayed the same but some changed:

  • Some playlist methods no longer get the user since the corresponding API removed them
  • Some parameter renaming to reflect spotify API naming, avoid shadowing builtins method or for better readability. Example: country rename to market

Reporting Issues

If you have suggestions, bugs or other issues specific to this library, file them here. Or just send me a pull request.

About

A light weight Python library for the Spotify Web API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%