Skip to main content

Another wrapper for the Spotify Web API, built on top of requests and requests_oauthlib.

I wrote this package as a kind of “code generation experiment”: the code (and doc) of Spotify class was almost entirely generated using a script that scrapes the official Spotify Web API documentation.

For scripts and desktop apps, this package (optionally) includes a flask server (meant to be run locally) to handle user authorization without requiring the user to manually copy and paste the OAuth2 callback URL (containing the token) from the browser to your app.

  • Free software: MIT license

Installation

If you don’t need the authorization flask app:

pip install spotipie

otherwise:

pip install spotipie[auth-app]

Usage

  1. Obtain your credentials as described here.

  2. (Optional) Store your credentials and redirection URI as environment variables:

    • SPOTIPIE_CLIENT_ID

    • SPOTIPIE_CLIENT_SECRET

    • SPOTIPIE_REDIRECT_URI;

    you could also use another prefix, SPOTIPIE is just the default one.

  3. To use the spotipie.Spotify client you first need to create an HTTP session and authenticate it. The Spotify constructor takes whatever behaves like a requests.Session. spotipie provides one session class for each of the three OAuth2 authorization flows supported by the Spotify API (see Authorization Flows); these classes are built on top of requests_oauthlib.OAuth2Session (by composition, not inheritance):

    • ClientCredentialsSession

    • AuthorizationCodeSession

    • ImplicitGrantSession

    To see how to create a session, see the Examples.

  4. Once you have an authenticated session, you can wrap it with the client and you’re ready to make any API call you want:

    spotify = Spotify(session)
    results = spotify.search('symphony', obj_type='playlist')

    See the API of the client here.

What OAuth2 flow should I use?

A backend web application should use:

  • the client credentials flow if it doesn’t need access to private user data;

  • the authorization code flow otherwise.

For scripts and desktop application… it’s more complicated. The recommended flow in this case is “Authorization code with PKCE” but it’s not supported by Spotify at the time I’m writing this.

It’s not recommended to distribute your code with your API secret key in it, so both the client credentials flow and the authorization code flow should not be used, unless you ask your users to use their own API keys; this can be acceptable if your target users are other developers.

The implicit grant flow was designed for apps that run in the browser but has been used for “native apps” too since it doesn’t need the client secret key; unfortunately, for native apps, it’s neither very safe nor convenient from a user perspective since the authorization is not refreshable.

Examples

All the examples assume your API credentials and redirect URI are stored as environment variables.

API Reference

https://spotipie.readthedocs.io/en/latest/api/spotipie.html

Changelog

Metadata

Release files for spotipie 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for spotipie 0.1.2
File Size Uploaded Provenance
spotipie-0.1.2.tar.gz 46.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for spotipie 0.1.2
File Interpreter ABI Platform
spotipie-0.1.2-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 81.9 kB

Release files / spotipie-0.1.2.tar.gz

Download URL spotipie-0.1.2.tar.gz
Size 46.9 kB
Tags Source
SHA-256 checksum
How to use checksums
837180679aefd04bc94edf8bcdcb154cbb5e8d94337eff2907dcb4d1716b4270
BLAKE2b-256 checksum
How to use checksums
93f8a5e04b8fa1fea87fbd8a7cae2c6d160df0cfe1f248ecf94ffc8fae6174bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.1 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.8.3

Release files / spotipie-0.1.2-py2.py3-none-any.whl

Download URL spotipie-0.1.2-py2.py3-none-any.whl
Size 35.0 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
2538e108c404b6fcb768ab321d72f23deb28b10adf6df0f764be5160c78beba5
BLAKE2b-256 checksum
How to use checksums
17a1d6e0084452a4e801c9cd1ac14388f7277c6e4eda91690b041bde3d350f07
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.1 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.8.3

Security for spotipie 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page