requirements.txt
# https://pypi.org/project/firebase-admin/
firebase-admin==2.16.0
main.py
from flask import jsonifyimport firebase_adminfrom firebase_admin import credentialsfrom firebase_admin import firestoreimport google.cloud.exceptions# this should solve the "The default Firebase app already exists." exceptioncred = credentials.ApplicationDefault()default_app = firebase_admin.initialize_app(cred, { 'projectId': '...',})db = firestore.client()def test_firestore(request): doc_ref = db.collection('test').document('5pSFOxspzl75hYZzjnut') try: doc = doc_ref.get() data = doc.to_dict() return jsonify(data) except google.cloud.exceptions.NotFound: return 'Not found'