← Back to Blogs

Viral Projects

How to Use the Spotify API to Analyze Your Music Taste

Why wait until December for Spotify Wrapped? Let's use Python and the Spotify API to analyze your "Happiness Score" and generate viral content today.

Data is cool, but music data is personal. Building a tool that tells people "Your music taste is 80% depressing" or "You exclusively listen to songs in the key of G Major" is one of the easiest ways to go viral on Twitter/X.

In this tutorial, we will use the Spotify Web API to fetch your top tracks and analyze their hidden "Audio Features."

🎧

The Secret Metrics

Spotify scores every song on metrics you can't see in the app: Danceability, Energy, and Valence (Musical Positiveness). We are going to expose them.

Step 1: Get Your Keys

You need to register your app with Spotify to get a Client ID.

  1. Go to the Spotify Developer Dashboard.
  2. Click "Create An App".
  3. Copy your Client ID and Client Secret.
  4. Set your Redirect URI to http://localhost:8888/callback.

Step 2: Connect with Python

We will use the spotipy library, which handles all the complex OAuth authentication for us.

Terminal
pip install spotipy pandas matplotlib
Python (analyze.py)
import spotipy
from spotipy.oauth2 import SpotifyOAuth
import pandas as pd

# Authenticate
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(
    client_id="YOUR_CLIENT_ID",
    client_secret="YOUR_CLIENT_SECRET",
    redirect_uri="http://localhost:8888/callback",
    scope="user-top-read"
))

# 1. Fetch your top 50 songs (Short Term = Last 4 weeks)
top_tracks = sp.current_user_top_tracks(limit=50, time_range='short_term')

track_ids = [track['id'] for track in top_tracks['items']]

Step 3: The "Vibe Check" (Audio Features)

This is where the magic happens. We send those Track IDs back to Spotify and ask for their "Audio Features."

Python (Cont.)
# 2. Get Audio Features
audio_features = sp.audio_features(track_ids)

# Convert to DataFrame for easy analysis
df = pd.DataFrame(audio_features)
df['track_name'] = [t['name'] for t in top_tracks['items']]

# 3. Calculate your "Vibe Score"
avg_valence = df['valence'].mean() * 100
avg_energy = df['energy'].mean() * 100

print(f"Your Happiness Score: {avg_valence:.1f}%")
print(f"Your Chaotic Energy: {avg_energy:.1f}%")

Step 4: Making it Viral (Visualization)

Nobody shares text. They share images. Let's create a radar chart that plots your music personality. This is the asset your users will post on Instagram Stories.

Python (Plotting)
import matplotlib.pyplot as plt
import numpy as np

# Categories to plot
categories = ['Danceability', 'Energy', 'Speechiness', 'Acousticness', 'Valence']
values = df[categories].mean().values.flatten().tolist()
values += values[:1] # Close the loop

# Create the Radar Chart
angles = np.linspace(0, 2 * np.pi, len(categories), endpoint=False).tolist()
angles += angles[:1]

fig, ax = plt.subplots(figsize=(6, 6), subplot_kw=dict(polar=True))
ax.fill(angles, values, color='#1DB954', alpha=0.25)
ax.plot(angles, values, color='#1DB954', linewidth=2)
ax.set_yticklabels([])
ax.set_xticks(angles[:-1])
ax.set_xticklabels(categories)

plt.title("My Spotify Vibe Check 2025", color='white')
plt.savefig('viral_chart.png', transparent=True)

Idea: How to Monetize This

You can wrap this script into a simple web app (using Flask or Streamlit).