Snippets

Here are some snippets showcasing how the library can be used.

Getting artist using API, PublicAPI and Genius

The following snippet will be the same for all methods that are available in API and PublicAPI (or have a public_api parameter if you’re using Genius).

from lyricsgenius import API, PublicAPI, Genius

api = API(token)
public = PublicAPI()
genius = Genius(token)

# API
api.artist(1665)

# PublicAPI
public.artist(1665)

# Genius
# can get it using both API and PublicAPI
genius.artist(1665)
genius.artist(1665, public_api=True)

All the songs of an artist

from lyricsgenius import Genius

genius = Genius(token)
genius.search_artist('Andy Shauf')
artist.save_lyrics()

YouTube URL of artist’s songs

import json
# we have saved the songs with artist.save_lyrics() before this
with open('saved_file.json') as f:
    data = json.load(f)
for song in data['songs']:
    links = song['media']
    if links:
        for media in links:
            if media['provider'] == 'youtube':
                print(print(['song'] + ': ' + media['url'])
                break

Searching for a song by lyrics

Using search_lyrics:

from lyricsgenius import Genius

genius = Genius(token)

request = genius.search_lyrics('Jeremy can we talk a minute?')
for hit in request['sections'][0]['hits']:
    print(hit['result']['title'])

Using search_all:

from lyricsgenius import Genius

genius = Genius(token)

request = genius.search_all('Jeremy can we talk a minute?')
for hit in request['sections'][2]['hits']:
    print(hit['result']['title'])