Python Firebase Real Time Database – in this Python article iam going to talk about Python Firebase Real Time Database.
So first of all Firebase is platform which allow to build web and mobile applications without server
side programming language. You can store users data on its real-time database which sync
data among users data in no time.
Firebase is a google product which offers so many useful features. Like
1: Firebase Real Time Database 2: Push Notifications 3: Firebase Authentication
4: Firebase Cloud Messaging 5: Firebase Test Lab For Android 6: Firebase Crash Reporting
7: Firebase Notification 8: Firebase App Indexing and many more
So in this article we are going to use Real Time Database Feature of Firebase.
OK when you want to use Firebase in Python you need to install some packages
pip install requests
pip install python-firebase
After installation you need to open Firebase Console and create a new project, you can check the video
and learn how to create your firebase projects.
So now this is the code for inserting data to Firebase Real Time database
1 2 3 4 5 6 7 8 9 10 |
from firebase import firebase firebase = firebase.FirebaseApplication('URL of Database', None) data = { 'Name': 'John Doe', 'RollNo': 3, 'Percentage': 70.02 } result = firebase.post('/python-example-f6d0b/Students/',data) print(result) |
OK now in this line of code FirebaseApplication takes two parameters; one is URL of database and second is authentication details for database
because for this project we have not set a rule by this reason we have given None in the second parameter.
1 |
firebase = firebase.FirebaseApplication('URL of Database', None) |
And in this line of code we are going to insert data to our table
1 |
result = firebase.post('/python-example-f6d0b/Students/',data) |
OK this was for inserting data and now we want to retrieve the data, you can use this code
Retrieving The Data
1 2 3 4 5 6 7 |
from firebase import firebase firebase = firebase.FirebaseApplication('URL of database', None) result = firebase.get('/python-example-f6d0b/Students/', '') print(result) |
Updating The Data
1 2 3 4 5 |
from firebase import firebase firebase = firebase.FirebaseApplication('Database URL', None) firebase.put('/python-example-f6d0b/Students/-LjLUhaWGuxNd5gOEmse','Name','Bob') print('Record Updated') |
Deleting The Data
1 2 3 4 5 |
from firebase import firebase firebase = firebase.FirebaseApplication('URL Of Database', None) firebase.delete('/python-example-f6d0b/Students/', '-LjLUhaWGuxNd5gOEmse') print('Record Deleted') |
Also you can watch the complete video for this article
Subscribe and Get Free Video Courses & Articles in your Email
it says it cant import firebase