How can I play a Spotify audio with Python?

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

Best answer

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.