Cypher: A Quick Way to Retrieve Music Lyrics

4 minute read | Updated:

[Cypher](https://github.com/tmthyjames/cypher) is a new `pip`-installable library that retrieves music lyrics without having to scrape the site yourself. If you want an artist's lyrics, just do the following:

Cypher is a new pip-installable library that retrieves music lyrics without having to scrape the site yourself. If you want an artist's lyrics, just do the following:

In [1]:
import thecypher as cy
coasts = cy.get_lyrics('coasts')
coasts[0]
2018-01-27 21:34:11,242 : INFO : GET Artist URL: http://lyrics.wikia.com/wiki/Coasts
2018-01-27 21:34:11,332 : INFO : GET Artist Album: Coasts (2016)
2018-01-27 21:34:12,362 : INFO : GET Artist Album Successful: Coasts (2016)
2018-01-27 21:34:12,363 : INFO : GET Artist Album: Misc (0000)
2018-01-27 21:34:12,364 : INFO : GET Artist Album Successful: Misc (0000)
Out[1]:
{'album': 'Coasts (2016)',
 'artist': 'coasts',
 'genre': 'Indie_Pop',
 'id': 0,
 'lyric': 'We fell in love',
 'song': 'Oceans',
 'year': '2016'}
That's it. You now have all of the lyrics for [Coasts](http://www.coastsband.com/) available on [LyricWiki](http://lyrics.wikia.com/). If you want to convert this to a pandas `DataFrame` then just do the following: 

That's it. You now have all of the lyrics for Coasts available on LyricWiki. If you want to convert this to a pandas DataFrame then just do the following:

In [2]:
import pandas as pd
coasts_df = pd.DataFrame(coasts)
coasts_df.head()
Out[2]:
album artist genre id lyric song year
0 Coasts (2016) coasts Indie_Pop 0 We fell in love Oceans 2016
1 Coasts (2016) coasts Indie_Pop 1 Right by the ocean Oceans 2016
2 Coasts (2016) coasts Indie_Pop 2 Made all our plans Oceans 2016
3 Coasts (2016) coasts Indie_Pop 3 Down on the sand Oceans 2016
4 Coasts (2016) coasts Indie_Pop 4 And from the tips of your fingers Oceans 2016
By default, the data is delivered with one lyric per row. The following code will convert it to one song per row:

By default, the data is delivered with one lyric per row. The following code will convert it to one song per row:

In [3]:
group = ['song', 'year', 'album', 'genre', 'artist']
coasts_by_song = coasts_df.sort_values(group)\
       .groupby(group).lyric\
       .apply(' '.join)\
       .reset_index(name='lyric')
    
coasts_by_song.head(2)
Out[3]:
song year album genre artist lyric
0 A Rush of Blood 2016 Coasts (2016) Indie_Pop coasts Are you looking for something? Are you searching for someone else? You say I feel better at midnight Because the moon is your only friend And I want you bad, Oh I knew that you wouldn't wanna go without I could be your hero, if you want me to You've got to show me how Like a rush of blood to the head You were crushing hearts till the end Like a rush of blood to the head You were crushing hearts till the end I'm a dreamer, I wanna be a better man I'll never be all that you wanted, But I'll give you everything that I can Like the greatest rush that you've ever felt When we hear the sound I could be your hero, if you want me to You've got to show me how Like a rush of blood to the head You were crushing hearts till the end Was a young love lost in the night Are we in too deep to decide? Put the beat in my heart, the words in my mouth Kept me out of the dark You put the taste I my tongue, the life in my soul Gave me air for my lungs Like a rush of blood to the head You were crushing hearts till the end Was a young love lost in the night Are we in too deep to decide?
1 As Long as I Need You 2016 Coasts (2016) Indie_Pop coasts As long as I need you For long as I want to I'll be your sole lover You'll be my only other Now we're chewing the fat Trying to get to the good stuff Breaking it up cause you know this is tough love Spending our nights in different places Keeping it live with the thrill of the chase As long as I need you For as long as I want to Now you've got no soul, never showing emotion Breaking me down, just a silent devotion Breathing deep to get a bit higher Color our cheeks the light of a fire It's getting easier to make out The words spilled from your mouth And at the end of the winter You said you'd love me forever Don't let the light go out Don't leave without a sound Don't let the light go out Don't leave without a sound The backseat of your car Three words taken too far By the end of the summer We were walking on water Don't let the light go out Don't leave without a sound Don't let the light go out Don't leave without a sound
Keep in mind that these lyrics are community generated and are not perfect (or complete in some instances), but I think LyricWiki is one of the best lyrics sites there is. 
I plan to convert this to a RESTful API and add more flexibility eventually. But for now, what you see is what you get. Enjoy!
To install with `pip`:

Keep in mind that these lyrics are community generated and are not perfect (or complete in some instances), but I think LyricWiki is one of the best lyrics sites there is.

I plan to convert this to a RESTful API and add more flexibility eventually. But for now, what you see is what you get. Enjoy!

To install with pip:

pip install thecypher