Why I Hate Pyrebase

in python β€’Β  4 years agoΒ 

image.png
source

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!
  1. Go to Firbase console
    Log in with your google account and create your project.
    1.png
    source

Like this πŸ‘‡
image.png

Just "Continue"
image.png

And "Create project"
image.png

Once project is created, add firebase to your app like this πŸ‘‡
I will pick web but you can add iOS or Android too.
image.png

Name your app and "Register app"
image.png

You will get a config data like this
image.png
(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
image.png
source

What am I using this for?
image.png

πŸ˜‰


image.png
➑️ Twitter

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!