PyBlog — Firebase Setup
Content
- Project Structure
- Firebase Setup
- Authentication
- Profile [WIP]
- Links [WIP]
- Final Remark [WIP]
Firebase Setup
On how to create a Firebase project check the below video
This will help you in how to create your firebase project. Now let’s setup the things which are required for PyBlog.
For Firestore, choose the options carefully. It might be different for your usecase.
Firebase Storage might be already enabled, but just recheck once. If not enable it for your project.
For more details check https://firebase.google.com/docs?authuser=0&hl=en on different options and settings related to Firebase.
Now let’s connect your newly created Firebase project to PyBlog.
We need the service account details of Firebase for Python to connect to it, check the below images from where you can get it
Now you have a .json file which has the details required, but those are very sensitive information so don’t share it with anyone.
Drag and drop the file to data/confidential directory in PyBlog
The name of the file is upto you, I will be using serviceAccountKey.json for PyBlog.
Why data/confidential directory? — Since it’s a very sensitive data, I will not like it to be pushed to VCS, so I added the data/confidential directory to .gitignore
And any file which is confidential can be put into this directory.
Now you have everything from Firebase which will help Python to connect to it. So let’s start coding in Python.
Let’s create few python files inside ./firebase python package,
Let’s create Firestore and Storage classes which will connect to Firebase Firestore and Storage and perform all the operations required
It’s time to connect them to the Firebase so that all the calls to these classes can be handled from one place and also the firebase_app is provided to them.
Let’s add Firebase class to our firebase Python package, so that it can be used outside the package when imported
Now we have a Firebase class which connects PyBlog to Firebase and also to Firestore and Storage.
There are few codes which might be unknown at the moment, but don’t worry will provide the details later. And you can also go to the GitHub repository to see the full code. Will provide all the details at the end of the article.
Let’s start with user authentication.