How to check if data exist in firebase. (KivyMD Python)

I’m new to Python and KivyMD. Also to working with Databases. I want to check if the data provided by the user using the KivyMD App is already in the Firebase Realtime Database. These are the data in the firebase.

Data in Firebase

The Code

def send_data(self, email):
    from firebase import firebase

    firebase = firebase.FirebaseApplication("https://infinity-mode-default-rtdb.firebaseio.com/", None)

    data = {
        'Email' : email
    }

    if email.split() == []:
        cancel_btn_checkpoint_dialogue = MDFlatButton(text='Retry', on_release=self.close_checkpoint_dialogue)
        self.checkpoint_dialog = MDDialog(title='Access Denied', text="Invalid Username"),
                                          buttons=[cancel_btn_checkpoint_dialogue])

        self.checkpoint_dialog.open()

    else:
        firebase.post('Users', data)

If the user enters an existing value in the database, that value should not be saved in the database. Also a Dialog box should be shown that the email is already in use. If the value provided by the user is not in the database it should be saved. Please help me to do this.

Answer

Did you try with firebase_admin?

I check my data with like this:

import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore

cred = credentials.Certificate(
        "firestore-cred.json"
    )
firebase_admin.initialize_app(cred)
db = firestore.client()
data = {
    "Email" : email
}

query_email = db.collection(u'Users') 
                .where(u"Email",u"==",data["Email"]) 
                .get()
if query_email:  
    # exists
    ...
else:
    # does not exist
    ...

If user email does not exist, query_email is going to be empty list. Do not forget that query_email is not json data. You can convert it json with to_dict():

email_query_result_as_json = query_email[0].to_dict()