Search code examples
pythonfirebasegoogle-cloud-firestore

Is there a way to use Google Firestore client in Python like in the Pyrebase library?


I am looking to create a client app in Python, that uses Firestore.
In the past I have used Pyrebase for python-written client apps.
From what I've read there is an official python client library for Firestore.

But, according to it's page (https://googleapis.dev/python/firestore/latest/index.html) it has some requirements that I can't understand how I'm supposed to fulfil, that weren't needed for the Pyrebase Realtime Database such as:

  • Requiring that I use GOOGLE_APPLICATION_CREDENTIALS that I assume mean the service account credentials json, which I can't do since I can't include these sensitive credentials in the client app.
  • Then, in the same page, in the quick start section it mentions that I should enable billing for my project, something that wasn't needed in Pyrebase.

Also I should enable "Google Cloud Firestore API". Is this required because this Firestore is a different service from Firebase's Firestore?

To sum up: How do I create a python client app that doesn't include sensitive info like the credentials json, and that only uses something along the lines of a Pyrebase Config dictionary (example included below).

import pyrebase

config = {
  "apiKey": "apiKey",
  "authDomain": "projectId.firebaseapp.com",
  "databaseURL": "https://databaseName.firebaseio.com",
  "storageBucket": "projectId.appspot.com"
}

firebase = pyrebase.initialize_app(config)

I'm completely lost on this, thanks in advance


Solution

  • The Python SDK that Google provides for Firestore (and that Firebase includes in its Admin SDK) relies on a set of credentials that provide it full, administrative access to the project. Because of this it is intended for use in a trusted environment, such as your development machine, a server that you control, or Cloud Functions/Cloud Run.

    The Pyrebase library accesses Firebase as an untrusted client through its REST APIs, so can be used in both trusted and untrusted environments.

    There is no official Firebase/Google SDK for accessing Firestore through Python from an untrusted client, so you're down to either accessing the REST API of Firestore (which is what Pyrebase does too for the APIs it supports), or finding another third party library.