This Jupyter notebook is designed to interact with the Spotify API to fetch and analyze data on top artists. It demonstrates how to authenticate with the API, retrieve data, and process it for analysis.
- Introduction
- Requirements
- Installation
- Usage
- Notebook Structure
- Important Functions
- Notes
- Contributing
- License
This notebook aims to provide a step-by-step guide to fetch data from the Spotify API. It covers the following aspects:
- Authentication with the Spotify API.
- Fetching data about top artists.
- Processing and visualizing the data.
To run this notebook, you will need:
- Python 3.6 or higher
- Jupyter Notebook
- Spotify Developer Account with a registered application to get the
client_id
andclient_secret
.
-
Clone the repository or download the notebook.
git clone https://github.com/yourusername/spotify-data-script.git cd sspotify-data-script
-
Install the required Python packages using pip:
pip install -r requirements.txt
The
requirements.txt
should contain:requests pandas matplotlib python-dotenv
-
Create a
.env
file in the same directory as your notebook and add your Spotify credentials:SPOTIFY_CLIENT_ID=your_client_id SPOTIFY_CLIENT_SECRET=your_client_secret
-
Open the Jupyter notebook.
jupyter notebook spotify.ipynb
-
Run the cells in order. The notebook will:
- Load the required libraries.
- Authenticate with the Spotify API using your credentials.
- Fetch data about the top 10 artists from a popular Spotify playlist.
- Display the data in a readable format and plot visualizations.
The notebook is divided into the following sections:
- Setup and Imports: Import necessary libraries and load environment variables.
- Authentication: Fetch Spotify API credentials and obtain an access token.
- Data Retrieval: Define functions to get data from the Spotify API.
- Data Processing: Process the retrieved data to extract relevant information.
- Visualization: Create visualizations to analyze the data.
get_token()
: Authenticates with the Spotify API and returns an access token.get_top_10_artists(access_token)
: Retrieves data about the top 10 artists from a specific Spotify playlist.
- Ensure that your Spotify API credentials are kept secure and not shared publicly.
- This notebook fetches data using the Spotify API, so you must comply with their terms of use.
- The API token has a limited validity period, and you may need to re-authenticate to get a new token.
Contributions are welcome! If you find any bugs or have suggestions for improvements, please create an issue or submit a pull request on the GitHub repository.
This project is licensed under the MIT License. See the LICENSE file for details.