I guess I should have used python-firebase... but I didn't pick python-firebase because there are two of them and I didn't know which one to choose π
But anyway, I started playing with Firebase the other day, and this python wrapper seemed pretty easy for firebase api.
What you have to do is pretty simple.
- Create a project on Firebase
- Add Firebase to your app
- Install pyrebase
And... start coing!
- Go to Firbase console
Log in with your google account and create your project.
source
Like this π
Just "Continue"
And "Create project"
Once project is created, add firebase to your app like this π
I will pick web but you can add iOS or Android too.
Name your app and "Register app"
You will get a config data like this
(this is not my config actually)
source
Project and app are all setup.
You only need this config part for python so copy and paste and make it like a real dictionary.
# Your web app's Firebase configuration
firebase_config = {
"apiKey": "fireBaeIzaSyDJIQ7LiBG7QK7dUBPW3M1cGBFPTw1BE",
"authDomain": "fireBae-9df46.firebaseapp.com",
"databaseURL": "https://fireBae-9df46.firebaseio.com",
"storageBucket": "fireBae-9df46.appspot.com",
}
Before you use Firebase in your python project, you need to install pyrebase library.
I have a better library so DO NOT actually install this library but this is how you install.
pip install pyrebase
Now the python part.
It is pretty simple.
import pyrebase
firebase_config = {
"apiKey": "fireBaeIzaSyDJIQ7LiBG7QK7dUBPW3M1cGBFPTw1BE",
"authDomain": "fireBae-9df46.firebaseapp.com",
"databaseURL": "https://fireBae-9df46.firebaseio.com",
"storageBucket": "fireBae-9df46.appspot.com",
}
firebase = pyrebase.initialize_app(firebase_config )
db = firebase.database()
This is pretty much it. You can just save data into firebase or retreive data from firebase.
Save Data
data = {
"username": "tomoyan"
}
results = db.child("users").push(data)
Retrieve Data
users = db.child("users").get()
for user in users .each():
print(user.key())
print(user.val())
using pyrebase is pretty simple, but a lot of stuff aren't working like this documentation.
https://github.com/thisbejim/Pyrebase
So that is why I hate pyrebase.
I use pyrebase4 instead.
So install this library
pip install pyrebase4
And the same code will work especially like these things
source
What am I using this for?
π
β‘οΈ Twitter