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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file spotify_py_sdk-0.1.2.tar.gz
.
File metadata
- Download URL: spotify_py_sdk-0.1.2.tar.gz
- Upload date:
- Size: 12.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8fa4cdd514b309c981dbb91aa77ceee927db2b5ce100d90c175f98f9e848b452 |
|
MD5 | 1fdbdd3f211ffc1ce4eb12bfe7d331d1 |
|
BLAKE2b-256 | 3f102b9be40991ada65d8ac9213ecf17807f270c640ecf4709d1bbcf3282b5a8 |
File details
Details for the file spotify_py_sdk-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: spotify_py_sdk-0.1.2-py3-none-any.whl
- Upload date:
- Size: 19.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 24935bbe3665a8305f5a3397ad2ebb6c88e7156ffdcedd7b79d6d2e4a8b5282f |
|
MD5 | 54054b0b7ea5b2c1f3ed86d9ff8f9146 |
|
BLAKE2b-256 | cab63cade53dd87ab68fd55470ca59c58af6218769c61b6f4362c72986a31eea |