https://github.com/rubynixx/spotify_analysis_using_spotipy
Utilising the Spotipy API to visualise personal listening patterns.
https://github.com/rubynixx/spotify_analysis_using_spotipy
data-visualization spotify spotipy spotipy-api spotipy-library
Last synced: over 1 year ago
JSON representation
Utilising the Spotipy API to visualise personal listening patterns.
- Host: GitHub
- URL: https://github.com/rubynixx/spotify_analysis_using_spotipy
- Owner: RubyNixx
- Created: 2024-09-09T21:55:25.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-09-10T20:33:30.000Z (over 1 year ago)
- Last Synced: 2025-01-10T17:43:53.601Z (over 1 year ago)
- Topics: data-visualization, spotify, spotipy, spotipy-api, spotipy-library
- Language: Jupyter Notebook
- Homepage:
- Size: 1.42 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Spotify Listening Stats
This project uses the Spotipy library in Google Colab to analyse personal Spotify listening data and provide headline statistics on listening activity.
Features
* Retrieves your top tracks and artists over different time ranges
* Calculates average audio features (danceability, energy, etc.) of your most-played tracks
* Generates a breakdown of your listening habits by genre
* Visualizes listening trends over time
Prerequisites
* Python 3.7+ (I used Google Colab)
* A Spotify account
* Spotify Developer credentials (Client ID and Client Secret)
Setup
1. Clone this repository:
[](https://github.com/RubyNixx/spotify_analysis_using_spotipy.git)
2. Set up your Spotify Developer account:
* Go to the Spotify Developer Dashboard
* Create a new app
* Note your Client ID and Client Secret
* Add http://localhost:8888/callback as a Redirect URI in your app settings
3. Set environment variables with your Spotify credentials:
Do not share your API client ID or client secret on Github
To handle this, i've used files with enviroment variables (.env) and utilised a .gitignore file to ensure sensitive information isnt included. I've then set and called them as variables within the python code.
Create a .env file and store in a secure place. See these instructions how to create a .env file:
https://github.com/RubyNixx/spotify_analysis_using_spotipy/blob/main/Steps_to_create_env_file.md
4. Run the main python script in google colab
[](https://colab.research.google.com/github/RubyNixx/spotify_analysis_using_spotipy/blob/main/spotipy.ipynb)
6. On first run, you'll be prompted to authorise the app to access your Spotify data. Follow the link provided to complete the authorisation process.
7. Sample Outputs:









The Spotipy library offers several key features for interacting with the Spotify Web API:
* Full API access: Spotipy provides access to all endpoints of the Spotify Web API, allowing you to retrieve a wide range of music data
* User authorisation support: The library supports both the Authorization Code flow and the Client Credentials flow for user authentication
* Lightweight and easy to use: Spotipy is designed to be a lightweight Python wrapper for the Spotify Web API, making it simple to integrate into your projects
* Comprehensive data retrieval: You can fetch information about artists, albums, tracks, playlists, user profiles, and more
* Search functionality: Spotipy allows you to search for items in the Spotify catalog
* Playlist management: You can create, modify, and delete playlists, as well as add or remove tracks
* User library interactions: The library enables you to access and modify a user's saved tracks and albums
* Audio features and analysis: You can retrieve audio features and detailed audio analysis for tracks
* Personalisation: Spotipy provides access to personalized data such as a user's top artists and tracks
* Follow/unfollow functionality: You can manage following/unfollowing artists, users, and playlists
* Browse and recommendations: The library allows you to access Spotify's browse and recommendation features
* Error handling: Spotipy includes built-in error handling for API requests
More information can be found here:
Spotipy API documentation:
https://spotipy.readthedocs.io/en/2.24.0/
Note: This will help with understanding the API & how to connect to it. I've included a clause in the python code to help work with the API in a google colab notebook.
Spotipy githib repo:
https://github.com/spotipy-dev/spotipy
Spotipy scopes:
https://developer.spotify.com/documentation/web-api/concepts/scopes#user-top-read
Stack overflow thread that helped with audio features:
https://stackoverflow.com/questions/38823403/scrape-deep-audio-features-using-spotipy-python-library
Exploring features of Spotify playlists - data collection code:
https://orda.shef.ac.uk/articles/code/Exploring_features_of_Spotify_playlists_data_collection_code/19107998
Other github repo inspiration utilising the API:
Using approaches likes PCA to reduce dimensions of data:
https://stmorse.github.io/journal/spotify-api.html
Some examples of how others have used it:
https://github.com/spotipy-dev/spotipy-examples/blob/main/showcases.ipynb