DEV Community

Alex Spinov
Alex Spinov

Posted on

Spotify Has a Free API — Search Tracks, Get Playlists, and Analyze Audio Features (No Premium Needed)

Spotify's Web API gives you programmatic access to the entire Spotify catalog — 100M+ tracks, playlists, artist data, and audio analysis. Free tier. No Premium subscription required.

If you've ever wanted to build a music recommendation engine, analyze listening trends, or create playlist generators — this is your starting point.

What You Get for Free

  • Search — query tracks, albums, artists, playlists, podcasts
  • Get track details — name, artist, album, duration, popularity score (0-100)
  • Audio features — danceability, energy, tempo, valence (happiness), acousticness
  • Audio analysis — beat-by-beat breakdown of any track (sections, segments, bars)
  • Playlists — read any public playlist, create/modify your own
  • User profiles — public profile data for any user
  • Recommendations — seed by tracks/artists/genres, get personalized suggestions
  • Rate limits: ~180 requests/minute (generous)

Quick Start: Search for a Track

import requests

# Step 1: Get access token (Client Credentials flow)
client_id = "your_client_id"
client_secret = "your_client_secret"

token_resp = requests.post("https://accounts.spotify.com/api/token",
    data={"grant_type": "client_credentials"},
    auth=(client_id, client_secret)
)
token = token_resp.json()["access_token"]

# Step 2: Search
resp = requests.get("https://api.spotify.com/v1/search",
    headers={"Authorization": f"Bearer {token}"},
    params={"q": "Bohemian Rhapsody", "type": "track", "limit": 1}
)
track = resp.json()["tracks"]["items"][0]
print(f"{track['name']} by {track['artists'][0]['name']}")
print(f"Popularity: {track['popularity']}/100")
Enter fullscreen mode Exit fullscreen mode

Getting Your API Credentials (3 Minutes)

  1. Go to developer.spotify.com/dashboard
  2. Log in with any Spotify account (free or premium)
  3. Click "Create App" — fill in name + description
  4. Copy your Client ID and Client Secret
  5. Set redirect URI (for user auth) or skip it (for server-to-server)

That's it. No approval process, no waitlist.

The Audio Features Nobody Knows About

This is Spotify's hidden gem. Every track has machine-learning-extracted features:

# Get audio features for any track
resp = requests.get(
    f"https://api.spotify.com/v1/audio-features/{track_id}",
    headers={"Authorization": f"Bearer {token}"}
)
features = resp.json()
Enter fullscreen mode Exit fullscreen mode

What you get:

Feature Range Example
danceability 0.0-1.0 "Stayin' Alive" = 0.87
energy 0.0-1.0 "Thunderstruck" = 0.98
valence (happiness) 0.0-1.0 "Happy" = 0.96
tempo BPM "Blinding Lights" = 171
acousticness 0.0-1.0 "Hallelujah" = 0.83
instrumentalness 0.0-1.0 Classical pieces near 1.0
speechiness 0.0-1.0 Podcasts/rap near 1.0

Build a mood-based playlist generator. Map energy + valence to "workout", "chill", "focus", "party".

Real Projects You Can Build

1. Playlist analyzer — Input a playlist URL, output average danceability, energy, and tempo. Show outlier tracks.

2. Music taste comparison — Compare two users' top artists. Calculate similarity score.

3. "Discover new artists" tool — Seed the recommendation endpoint with a user's top 5 tracks, return artists they've never heard.

4. Mood ring for playlists — Visualize a playlist's emotional arc using valence over track order.

5. Genre explorer — The API has 126 genre seeds. Build a map that lets users explore adjacent genres.

Recommendation Engine in 10 Lines

# Get recommendations based on seed tracks
resp = requests.get("https://api.spotify.com/v1/recommendations",
    headers={"Authorization": f"Bearer {token}"},
    params={
        "seed_tracks": "4uLU6hMCjMI75M1A2tKUQC",  # Bohemian Rhapsody
        "target_energy": 0.8,
        "target_danceability": 0.7,
        "limit": 10
    }
)
for track in resp.json()["tracks"]:
    print(f"{track['name']} - {track['artists'][0]['name']}")
Enter fullscreen mode Exit fullscreen mode

Tune recommendations by setting target values for any audio feature. The API handles the rest.

Auth Flows (Pick the Right One)

Flow Use case User login?
Client Credentials Search, public data, audio features No
Authorization Code User's playlists, top tracks, playback Yes
PKCE Same as above, for SPAs (no server) Yes
Implicit (deprecated) Don't use this Yes

For most data projects, Client Credentials is enough and requires zero user interaction.

Rate Limits and Quotas

  • ~180 requests/minute (varies by endpoint)
  • No hard daily limit documented (but sustained heavy use may trigger throttling)
  • 429 Too Many Requests — check Retry-After header
  • Token expires every 60 minutes — refresh automatically

Tip: cache responses. Track metadata rarely changes.

What You Can't Do

  • Stream music (you get 30-second preview URLs, not full tracks)
  • Access other users' private playlists without their OAuth consent
  • Bulk download the catalog (that's a licensing issue, not API)
  • Commercial use without Spotify's approval (read their TOS)

Links


Building data tools and scrapers? I've published 88+ ready-made Apify actors for web scraping — Reddit, YouTube, Trustpilot, HN, and more.

Need a custom solution? spinov001@gmail.com

More "[Brand] Has a Free API" articles:
Discord | Hacker News | Supabase | CoinGecko

Top comments (0)