Reputation: 379
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.
Upvotes: 5
Views: 7132
Reputation: 21
You can't use
firebase_admin.firestore
but you can use
from firebase_admin import firestore
Hope this helps !
Upvotes: 1
Reputation: 420
faced the same issue, adding the following import worked for me
from firebase_admin import firestore
Upvotes: 10
Reputation: 4660
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!
Upvotes: 0