Python Firebase SDK Integration with Realtime Database

In this Python Firebase article iam going to show you Firebase SDK Integration

with Realtime Database. With the Admin SDK, you can read and write Realtime Database

data with full admin privileges, or with finer-grained limited privileges. also Admin SDK lets

you interact with Firebase from privileged environments to perform actions like:

 

  • Read and write Realtime Database data with full admin privileges.
  • Programmatically send Firebase Cloud Messaging messages using a simple, alternative approach to the Firebase Cloud Messaging server protocols.
  • Generate and verify Firebase auth tokens.
  • Access Google Cloud Platform resources like Cloud Storage buckets and Cloud Firestore databases associated with your Firebase projects.
  • Create your own simplified admin console to do things like look up user data or change a user’s email address for authentication.

 

 

You can check the complete video tutorial for this article at the end.

 

 

More Python Firebase Tutorials 

1: Python Firebase Admin SDK Integration & Realtime Database

2: Python Firebase Full Course For Beginners 

 

 

 

If you are interested in Python Firebase Admin SDK, read the below articles 

1: Firebase SDK Integration with Real Time Database

2: Firebase SDK working with Cloud Firestore 

3: Python Firebase SDK Working with Authentication

 

 

 

 

You can check Firebase Admin SDK features that are available for different programming

languages in this link, Firebase Admin SDK Features .

 

 

 

 

Setup Firebase Project & Service Account

To use the Firebase Admin SDKs, you’ll need the following:

  • A Firebase project
  • A service account to communicate with Firebase
  • A configuration file with your service account’s credentials

 

 

 

OK so after creation of your project in Firebase Console, you need to enable Realtime

Database in your project. after that for integration of Firebase SDK you need to install the

SDK for the language of your choice. because we are using python, so we do the process for

python programming language. you can easily install Firebase Admin SDK with pip like this.

 

To authenticate a service account and authorize it to access Firebase services, you must

generate a private key file in JSON format.

 

  1. In the Firebase console, open Settings > Service Accounts.
  2. Click Generate New Private Key, then confirm by clicking Generate Key.
  3. Securely store the JSON file containing the key.

 

 

 

 

and add that json file to your working directory.

Python Firebase SDK Integration with Realtime Database
Python Firebase SDK Integration with Realtime Database

 

 

 

 

Admin SDK Integration 

Before you can access the Firebase Realtime Database from a server using the Firebase Admin

SDK, you must authenticate your server with Firebase. When you authenticate a server, rather

than sign in with a user account’s credentials as you would in a client app.

 

When you initialize the Firebase Admin SDK with the credentials for a service account with

the Editor role on your Firebase project, that instance has complete read and write access to

your project’s Realtime Database.

 

 

 

 

 

 

So in the above code this is for fetching the service account key json file. and make that

you have downloaded the key and added that to your working directory.

 

 

 

 

 

Because we are working with Realtime Database, so after enabling Reatime Database you

need to add the url of the database.

 

 

 

 

 

Now the setup is completed we need to add some data to our realtime database using this code.

 

You can use set for adding data to your realtime database.

 

 

 

 

 

For updating you need to add this code.

 

 

 

 

 

If you want to work with multiple path update, you can use this code.

 

 

 

 

 

There is also another way that you can add data, using this way you can create key for your data,

in the first way that we have used for adding data, there is no key for our data.

 

 

 

 

 

You can retrieve the data easily using this code.

 

 

 

 

 

This is the complete code for this article.

 

 

 

 

 

 

Also you can watch the complete video for this article

Subscribe and Get Free Video Courses & Articles in your Email

 

1 thought on “Python Firebase SDK Integration with Realtime Database”

Comments are closed.

Share via
Copy link
Powered by Social Snap
×