I started reverse-engineering Spotify's web player when I was 15. Almost three years later, that little experiment has become an open-source Python library called SpotAPI.
If you're building a music-related side project and just want to search Spotify's public catalogue, here's how to get started without registering a developer application.
Installation
You'll need Python 3.11 or newer.
python -m pip install spotapi
You can immediately search Spotify from your terminal:
python -m spotapi search "Daft Punk"
No developer account, client ID or client secret is required for this public search.
Searching Spotify with Python
import asyncio
from spotapi import Public
async def main() -> None:
results = await Public.search("Daft Punk", limit=5)
for track in results.tracks:
print(track.name, track.uri)
asyncio.run(main())
The results are typed Python models, so you can explore their attributes using your editor's autocomplete.
Fetching artist information
If you're making multiple related requests, you can reuse a catalogue session:
import asyncio
from spotapi import Catalogue
async def main() -> None:
async with Catalogue() as spotify:
results = await spotify.search("Daft Punk")
if results.artists:
artist = await spotify.get_artist(
results.artists[0].uri
)
print(artist.name)
asyncio.run(main())
Exploring Spotify interactively
I also built a terminal interface for exploring Spotify's public catalogue.
python -m pip install "spotapi[demo]"
python -m spotapi discover "Daft Punk"
You can navigate search results and explore metadata directly from your terminal without signing in.
What about playlists and playback?
SpotAPI also supports authenticated account operations, playlist management and control of existing Spotify players. Those operations require your own Spotify session.
The library does not stream or decrypt music.
One important distinction: SpotAPI uses unofficial web-player endpoints, so Spotify can change their behaviour without notice. If you're building something that depends on officially supported contracts, the official Spotify Web API may be a better choice.
What would you build?
I'd love to see what other developers make with this. The project started as something I built out of curiosity in high school, and I'm still discovering interesting uses for it.
Source code: https://github.com/Aran404/SpotAPI
Documentation: https://the-open-odyssey.pages.dev/docs/spotapi/
SpotAPI is open source under GPL-3.0.
Top comments (0)