Firestore AttributeError: module 'firebase_admin' has no attribute 'firestore'

Viewed 2982

I encountered a problem when importing the Firestore module from package firebase_admin.

import firebase_admin
from firebase_admin import credentials

cred = credentials.ApplicationDefault()  

firebase_admin.initialize_app(cred, {
  'projectId': "...",
})

db = firebase_admin.firestore.client()

i installed the firebase_admin package using:

pip install --upgrade firebase-admin

But it returned:

AttributeError: module 'firebase_admin' has no attribute 'firestore'

I wonder if i missed something.

2 Answers

faced the same issue, adding the following import worked for me

from firebase_admin import firestore 

The import part is correct. You did the import of the library and resources correctly.

However, the part of the db = firebase_admin.firestore.client() it's not completely well set. This method needs a parameter for it to be called correctly. As it's explained in the official documentation here:

Parameters: app – An App instance (optional)

So, even if you don't to send a specific app, you need to set it as none, for the method to be called correctly. Another example of how to call the method can be found in the official repository from Firebase, accessible via this link.

Let me know if the information helped you!

Related