The Genius class

class tflyrics.genius.Genius(token: str = None, api_url: str = None)

A proxy to the Genius API.

A Genius object is a proxy to access the Genius song lyrics API. Each Genius object has a token with which it can access the API, and provides instance methods to query the API in different ways, each time using its access token.

Getting the lyrics of a song or set of songs, getting the songs by an artist, and getting an artist’s unique ID on the API are among the methods that a Genius object offers.

static artist_name_parts(complex_name: str, min_length: int = 10) → list

Get the names of artists that have been joined into a bigger name.

Get a list containing the names of artists that have been joined to form a larger, composite name: for example get [‘Sting’, ‘The Police’] from ‘Sting and The Police’, or from ‘Sting & The Police’. An optional minimum length can be provided, under which no attempts are made to find artist names inside the composite name (which is then assumed to be a non-composite name that happens to contain special characters).

Parameters

complex_name – composite name (name containing multiple names)

Min_length

the minimum length that a name must have to be split

Returns

the (sorted) list of artists that form a composite name

get_artist_id(artist_name: str) → int

Get the Genius ID of an artist.

Get the unique identifier of an artist in the Genius database, by providing the name of the artist. Returns -1 if no match can be found.

Parameters

artist_name – the name of the artist

Returns

an integer that uniquely identifies the artist

get_text(song_id: int) → str

Get the lyrics of a song identified by a string.

Get the lyrics of a song, by providing its identifier on Genius.

Parameters

song_id – the identifier of a song on Genius

Returns

the lyrics of that song

request(endpoint: str = '/', params: dict = {}) → dict

Get the response to a request sent to the Genius API.

Get the response of the Genius API to an HTTP GET request. The response is a dictionary (or None, if the status code was not between 200 and 400). The GET request is sent to an optionally specified end-point, with optional query parameters.

Parameters
  • endpoint – the endpoint of the request to the Genius API

  • params – a dictionary containing parameters to the request

Returns

a dictionary representing the response of the API

resources(artist_name: str, n_songs: int = 5) → int

Generate the IDs of popular songs by a certain artist.

One at a time, yield the unique identifiers of popular songs by a certain artist, given the artist’s name and the amount of songs to be retrieved.

Parameters
  • artist_name – the name of an artist

  • n_songs – the amount of songs to be retrieved

Yield

an integer that uniquely identifies the song