A simple API object that helps me to consume Spotify API data, and helps me with other projects.
Explore the docs »
·
Report Bug
·
Request Feature
Table of Contents
I am currently working on a project based on the Spotify API consume, so I decided to create my own api object to make my life easier C: This is completely personalized to my needs and I will update it when I need it.
If you want to try it, you need a virtual environment with Python 3.9+ and pip installed in your computer.
As I said above you will need Python 3.9+ and pip3 installed in your computer, also you will need to install some libraries, to do that you will need to download the project and run a pip command as you will see on the installation section.
- Get a free API Key and Secret at Spotify for Devs!
Strong recommendation, set a Callback URI
- Install the library
pip install bbfy
- Store you keys and Callback URI in a .env or another kind of secret file
SPOTIFY_CLIENT_ID=your actual client_id
SPOTIFY_CLIENT_SECRET=your actual client_secret
SPOTIFY_CALLBACK_URI=your actual callback_uri
- You are Ready
For now you can only recolect users info, the top tracks or artists for this user and the recently played tracks.And it is optimized to use with Flask
and Django
, I will use Flask on this next steps:
- Create a bubufy instance with your respective keys:
bubufy = Bubufy(client_id, client_secret, callback_uri)
- Get the authorization url and go to give access to use the API
auth_url = bubufy.get_auth_url()
You can access to this url through a button in your Flask, an example of this would be
@app.route('/route_name')
def method_name():
context = {
'auth_url': auth_url,
}
return render_template('template_name.html', **context)
And on your HTML could be something like:
<a href="{{ auth_url }}">Hi! Authorize me!</a>
- Give the app access, get the code from the redirect url and set the token with the following methods:
@app.route('/callback_uri')
def callback_name():
code = request.args.get('code')
bubufy.set_code_for_token(code)
bubufy.set_token()
return redirect(url_for('index')) # This for security or better UX
- And now you have a functional api in the
bubufy
object, you can make some things with it, for example, let's print the username in our page (Don't forget this is a flask project):
@app.route('/username')
def username_route():
username = bubufy.get_user_data()['display_name']
return username
You can make other things, I will soon update the documentation.
See the open issues for a list of proposed features (and known issues).
Hi there! You want to contribute! Let me now how with your PR!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE
for more information.
David (Bubu) - @DBubu73 - david.pedroza.segoviano@gmail.com
Project Link: https://github.com/BubuDavid/Bubufy