19

I would like to know if it's possible to play songs from Spotify with Python (version 2.7 if possible) and how.

jonrsharpe
  • 99,167
  • 19
  • 183
  • 334
NeoMahler
  • 363
  • 1
  • 2
  • 6
  • I see people voting "against" the question... but I need an answer. Does that mean that it's not possible or that you are too lazy to answer? – NeoMahler Aug 31 '15 at 10:46
  • 4
    Neither; it means that it's not an appropriate question for Stack Overflow, irrespective of whether or not you *"need an answer"*. Please take the [tour] and read [ask]. – jonrsharpe Aug 31 '15 at 11:02
  • 2
    Ok, I read the tour. But I don't understand... In the Don't ask about section: Questions you haven't tried to find an answer for (show your work!) --> I didn't try to connect to spotify because I don't have idea on how to make it. I tred with YouTube (it didn't work). But that's not what I'm asking. In the How to Ask, I see that I have to introduce. Ok, introduction: I'm going to make a program that will play spotify music. Reproduce the problem: open the spotify and code in python. Is this the solution? I think that's the problem you are talking about, but I don't see where the problem is. – NeoMahler Aug 31 '15 at 11:40
  • 1
    *"I didn't try to connect to spotify because I don't have idea on how to make it"* - then you aren't ready to ask a question here yet; do some more research. – jonrsharpe Aug 31 '15 at 11:46

2 Answers2

17

Although I understand that you're being downvoted since the question isn't very well-formed, I would like to give you an answer.

There are several ways to interact with Spotify, where the post popular right now is the Web API. The Web API offers a lot of features, but not playback of full tracks. Therefore, it doesn't matter if you're using Python, Java, C#, or whatever language, you'll still not be able to play music using the Web API. There are however mobile SDKs that support playback, available for both Android and iOS.

You can however play preview tracks (30 seconds) using the Web API. Check out spotipy, it's one of the better Python clients, if not the best.

There are other ways to interact directly with the Spotify desktop application, but none that are supported officially by Spotify, and I can't recommend them since they may stop working at any point in time.

Edit: As the other answer to this question correctly states, Libspotify could solve this problem for you. The reason I didn't mention it is that it's deprecated. We're aiming to have a replacement for it by the end of 2015.

Michael Thelin
  • 4,332
  • 2
  • 21
  • 29
4

With pyspotify you get access to all of the (old, but still working) libspotify API and you can play full tracks. It works on Python 2.7 as well as Python 3.2+ and PyPy.

jodal
  • 193
  • 4