UnWrapped is a FastAPI application that allows users to get their Spotify Wrapped and other stats any time of the year. It provides endpoints to view top tracks, top artists, playlists, and more.
- View your top tracks and artists for different time ranges.
- View and manage your playlists.
- Cache user data for improved performance.
- Refresh Spotify tokens automatically.
- Python 3.8+
- PostgreSQL
- Spotify Developer Account
-
Clone the repository:
git clone https://github.com/yourusername/unwrapped.git cd unwrapped
-
Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install the dependencies:
pip install -r requirements.txt
-
Set up environment variables:
Create a
.env
file in the root directory and add the following variables:CLIENT_ID="" CLIENT_SECRET="" REDIRECT_URI="" POSTGRES_URL="" SECRET_KEY="" SECRET_SALT=""
-
Start the FastAPI application:
uvicorn main:app --reload
-
Open your browser and navigate to
http://localhost:8000
.
- GET /login: Redirects to Spotify login page.
- GET /callback: Handles Spotify callback and user authentication.
- GET /logout: Logs out the user.
- GET /: Home page showing user info.
- GET /profile: User profile page.
- GET /playlists: User playlists page.
- GET /playlist: View a specific playlist.
- GET /toptracks: View top tracks.
- GET /topartists: View top artists.
- GET /static/fonts/{font_name}: Serve font files.
- GET /static/logo/{logo_name}: Serve logo files.
- GET /spotify_logo: Serve Spotify logo.
- HEAD /ping: Health check endpoint.
User data is cached using cachetools.TTLCache
to improve performance. The cache is set to expire after 30 seconds.
Errors during the callback process are logged and appropriate error messages are returned to the user.
Logging is configured to output debug information to the console.
To deploy the application, you can use any ASGI-compatible server such as Daphne, Uvicorn, or Hypercorn. Make sure to set the environment variables and configure the database connection appropriately. The structure of .env is given in example
This project is licensed under the AGPL-3.0 License. See the LICENSE file for details.