Connecting Firebase to Python

Complete guide with detailed steps to connect your real-time database on Firebase to Python.

NamyaLG
TheLeanProgrammer
3 min readJun 17, 2021

--

Through this blog, I will provide the steps that are necessary to connect your real-time database on Firebase to Python. I am assuming you have already created a Firebase project and set up the real-time database.

Installation and Dependencies

This is the only installation that is necessary. During installation, I faced an issue installing one of the dependencies, as a remedy, I followed these steps to complete the installation. My working environment is WSL or Windows Subsystem For Linux

pip3 or pip can be used alternatively based on the Python version

Code and Procedure

This is the code required to connect python to your firebase real-time database

secret key.json

This secret key needs to be downloaded and will be available at

Project Settings -> Service Accounts -> Generate a new private key

Step 1
Click on Service accounts
Click on this to generate a new private key

A JSON file will be downloaded and it needs can be placed in the same folder as your python script.

URL to database

This refers to the URL provided to access your database which will be provided under the configuration information

Use the databaseURL provided

Database Reference

This refers to the node that needs to be accessed in the database

Example database

If Soil Moisture is the node that has to be referenced, then, line 12 can be written as :

Now, you will be able to perform CRUD based on the documentation!

Don’t forget to follow The Lean Programmer Publication for more such articles, and subscribe to our newsletter tinyletter.com/TheLeanProgrammer

--

--

NamyaLG
TheLeanProgrammer

Tech-enthusiast | Runner_for_life | #NoHumanIsLimited