Search Genius Songs with Python and lyricsgenius
A short Python script that searches the Genius API for a song with the lyricsgenius library and prints its title, artist, album, and a lyrics preview.
Python projects · Music and APIs
Start here
Read the requirements and any configuration below, then follow the usage example. Source paths below are relative to the repository root; run commands from the working directory stated in Usage. This example’s source is in Lyrics/Console_Code/. Install any third-party packages in an isolated Python environment.
Overview
This script searches for a song by title and artist name using the Genius API, cleans the retrieved lyrics by stripping section headers (e.g., [Verse 1]), and prints the song’s metadata along with a preview of the lyrics (up to 1,000 characters).
Features
- Searches the Genius database by song title and artist name
- Removes section headers (e.g.,
[Chorus],[Bridge]) from lyrics using regex - Displays song title, artist, album, and a 1,000-character lyrics preview
- Skips remixes and live recordings via
excluded_terms - Suppresses non-song results using
skip_non_songs
Prerequisites and installation
lyricsgenius
Install the dependency:
python -m pip install lyricsgenius
Configuration
Open Lyrics.py and update the following variables:
| Variable | Description |
|---|---|
genius API token |
Replace the token string with your own Genius API token |
song_title |
The title of the song to search for |
artist_name |
The artist’s name |
To get a Genius API token, register at genius.com/developers and create a new API client.
Usage
From the Console_Code folder:
python Lyrics.py
Output Format
🎵 Title: <song title>
🎤 Artist: <artist>
💿 Album: <album full title>
🎶 Lyrics:
<first 1,000 characters of the lyrics>...
If no match is found, the script prints Song not found.
Architecture
Lyrics/
└── Console_Code/
└── Lyrics.py # Main script
Troubleshooting and limitations
- Use your own Genius API token. Do not commit a real token to source control — read it from an environment variable instead, for example
lyricsgenius.Genius(os.environ["GENIUS_ACCESS_TOKEN"]). song.albumcan beNonefor songs without an album on Genius, which would make thesong.album.full_titleline fail.- The script does not catch authentication, network, rate-limit or other service exceptions. A search returning
Nonefollows the not-found branch; an exception follows the dependency’s error behavior and can terminate the script. - Only the first 1,000 characters of the lyrics are printed in the current implementation.
Related documentation
Documentation links
Read all Python Projects and Code Examples guides online · Project overview · All developer projects