https://github.com/steinitzu/spotify-api
Spotify web API client for Python
https://github.com/steinitzu/spotify-api
Last synced: 3 months ago
JSON representation
Spotify web API client for Python
- Host: GitHub
- URL: https://github.com/steinitzu/spotify-api
- Owner: steinitzu
- License: mit
- Created: 2017-07-05T22:23:28.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2022-12-07T23:42:04.000Z (over 2 years ago)
- Last Synced: 2024-10-08T01:17:41.997Z (8 months ago)
- Language: Python
- Homepage:
- Size: 29.3 KB
- Stars: 8
- Watchers: 3
- Forks: 2
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# spotify-api
Python API client for the spotify web API.
[https://developer.spotify.com/web-api/](https://developer.spotify.com/web-api/)# Usage
## Intro
```python
from spotify import Client, OAuthauth = OAuth('MY_CLIENT_ID', 'MY_CLIENT_SECRET')
auth.request_client_credentials()client = Client(auth)
albums = client.api.search('artist:frank zappa', type='artist', 'album')
```## Flask example with OAuth
```python
from flask import Flask, redirect, request, session, url_for, jsonify
from spotify import OAuth, Clientapp = Flask(__name__)
app.config['SECRET_KEY'] = 'supersecret'def get_auth(token=None):
auth = OAuth(
'MY_CLIENT_ID',
'MY_CLIENT_SECRET',
redirect_uri='http://my_redirect_uri',
scopes=['user-read-private', 'user-top-read']
)
auth.token = token
return auth
@app.route('/the_app')
def the_app():
token = session.get('spotify_token')
if not token:
return redirect(url_for('authorize'))
client = Client(get_auth(token))
return jsonify([
client.api.me(),
client.api.me_top('artists')
])
@app.route('/authorize')
def authorize():
auth = get_auth()
return redirect(auth.authorize_url)
@app.route('/callback') # redirect uri should point to this
def callback():
auth = get_auth()
auth.request_token(request.url)
session['spotify_token'] = auth.token
return redirect(url_for('the_app'))
```