Skip to main content

Python SDK for Spotify

Project description

Python SDK for Spotify Web API

This library is still a work in progress.

This is a Python library for the Spotify Web API. This SDK is very simple to use if you are already familiar with the typescript SDK provided by Spotify. It takes a lot of help from there.

Endpoints currently available

  • albums
  • artists
  • audiobooks
  • browse
  • chapters
  • episodes
  • markets
  • playlists
  • recommendations
  • search
  • shows
  • tracks
  • users

Requirements

  • python 3.9 or higher

Using this in your project

This library is yet not published on PyPI :) if you want to test the sdk out, you can clone this repo and follow the below mentioned steps to get results back. You can make changes in the already given example file or can simply run the tests using pytest to see if everything is working well or not.

Running the example provided

First install the dependencies (make sure you have poetry installed):

poetry install

Create a .env file in the root directory with your client_id and client_secret. Refer the .env.example file for reference.

CLIENT_ID=
CLIENT_SECRET=

Now run the file to get results back from the web api:

python example.py

Create a client instance

Currently, we only have client credentials flow for authentication. If you're building a server side application, you should use Client Credentials Flow, and is the correct choice when you have both your Client ID and Client Secret available.

from spotify-py-sdk import SpotifyApi, SdkConfig
from dotenv import load_dotenv
load_dotenv()

config = SdkConfig() # optional; can create custom methods
api: SpotifyApi = SpotifyApi(os.getenv("CLIENT_ID"), os.getenv("CLIENT_SECRET"), config)

Once you have an authenticated instance of the SDK, you can make requests to the Spotify Web API by using the methods exposed on the client instance of the API.

api.search.execute("purpose", ["album"])
api.browse.get_categories()

Running the tests

To run the tests, you need to have a Spotify account.

You will need to create a new app in the Spotify Developer portal, and add a redirect URI of http://localhost:3000.

You will need to add the following environment variables:

  • CLIENT_ID
  • CLIENT_SECRET

You can run the tests using pytest. We support python-dotenv, so you can add these to a .env file in the root of the repository.

To run all tests:

pytest

To run a specific test.

pytest tests/endpoints/test_albums.py

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spotify_py_sdk-0.1.2.tar.gz (12.3 kB view hashes)

Uploaded Source

Built Distribution

spotify_py_sdk-0.1.2-py3-none-any.whl (19.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page