A FastAPI-based REST API for managing songs and their lyrics with automatic enrichment from external music APIs.
- CRUD Operations: Create, read, update, and delete songs
- Search Functionality: Search songs by title, artist, release date range, external link, or lyrics keywords
- Automatic Enrichment: Automatically fetch release dates and lyrics from external APIs (Genius)
- Verse-by-Verse Access: Page through lyrics instead of loading all at once
- Flexible Architecture: Easy to switch between different music API providers
pip install -r requirements.txt
Go to https://genius.com/api-clients
Click "Generate Access Token"
Copy the token and add it to your .env
file
DATABASE_URL=sqlite:///./song_library.db
MUSIC_API_TOKEN=your_genius_api_token_here
MUSIC_API_BASE_URL=https://api.genius.com
The API is configured through environment variables:
DATABASE_URL
: SQLite database URL (default:sqlite:///./song_library.db
)MUSIC_API_TOKEN
: Genius API access token (optional)MUSIC_API_BASE_URL
: Base URL for the music API (default:https://api.genius.com
)
uvicorn app.main:app --reload
Once running, visit:
- Interactive API docs: http://localhost:8000/docs
- Alternative docs: http://localhost:8000/redoc
POST /songs/
- Create a new song (auto-enriched)GET /songs/
- List all songsGET /songs/{song_id}
- Get a specific songPUT /songs/{song_id}
- Update a songDELETE /songs/{song_id}
- Delete a songGET /songs/search
- Search songs with filtersGET /songs/{song_id}/verses
- Get paginated versesPOST /songs/{song_id}/enrich
- Manually trigger enrichmentPOST /songs/{song_id}/verses
- Manually add verses
title
: Search by song title (partial match)artist
: Search by artist name (partial match)release_date_from
: Filter by minimum release daterelease_date_to
: Filter by maximum release dateexternal_link
: Search by external linklyrics_keyword
: Search for keywords in lyrics
id
: Primary keytitle
: Song titleartist
: Artist namerelease_date
: Release date (nullable)external_link
: Link to external source (nullable)created_at
: Creation timestampupdated_at
: Update timestamp
id
: Primary keysong_id
: Foreign key to songsverse_number
: Order of versecontent
: Verse textverse_type
: Type (verse, chorus, bridge, etc.)
The API works without a Genius token, but without automatic enrichment:
- Create songs - Will create basic entries without release date or lyrics
- Manually add data:
- Use
PUT /songs/{id}
to add release date and external link - Use
POST /songs/{id}/verses
to add lyrics manually
- Use
- All search and pagination features still work
The project follows a clean architecture pattern:
- Routers: Handle HTTP requests and responses
- CRUD: Database operations
- Services: External API integration and web scraping
- Models: SQLAlchemy ORM models
- Schemas: Pydantic models for validation
- Database: Database connection and session management
- Some songs may not have lyrics on Genius
- The scraper may need adjustments for certain page formats
- Check console logs for scraping errors