The Firebase Admin Python SDK enables server-side (backend) Python developers to integrate Firebase into their services and applications. It provides programmatic access to Firebase services from trusted environments, allowing for tasks such as custom authentication, managing user data, sending FCM messages, and accessing Cloud Firestore and Storage. The current version is 7.3.0, and it maintains a regular release cadence with frequent updates.
pip install firebase-adminVerified import paths — ran on the pinned version, not inferred.
Initializes the Firebase Admin SDK using service account credentials (preferably from an environment variable) or Application Default Credentials. It then demonstrates connecting to Cloud Firestore, adding a new document to a collection, and reading all documents from that collection. Remember to replace placeholder project IDs and URLs, and secure your service account key.
Upgrade your Python environment to 3.10 or newer.
Migrate to `send_each()` and `send_each_for_multicast()` or their asynchronous counterparts `send_each_async()` and `send_each_for_multicast_async()`.
No direct fix required for `firebase-admin` itself, but review your project's `requirements.txt` if you previously relied on this transitive dependency.
Update `ActionCodeSettings` to use the `link_domain` parameter instead of `dynamic_link_domain`.
If real-time updates are critical, consider alternative SDKs (e.g., Node.js, Java) or implement a polling mechanism on the Python backend.
Store the path to the service account key in an environment variable (`FIREBASE_SERVICE_ACCOUNT_KEY_PATH`) or use Google Application Default Credentials when deploying on Google Cloud infrastructure.
Ensure Application Default Credentials are configured by setting the `GOOGLE_APPLICATION_CREDENTIALS` environment variable to the path of a service account key file, or by running `gcloud auth application-default login` for local development. For Google Cloud environments (e.g., GCE, GKE, Cloud Functions), ensure the service account associated with the environment has the necessary IAM roles.
Ensure `firebase-admin` is installed in the correct environment by running: `pip install firebase-admin` or `pip3 install firebase-admin`.
Initialize the app once, or check if an app already exists before initializing. For multiple apps, provide a unique name:
```python
import firebase_admin
from firebase_admin import credentials
if not firebase_admin._apps:
cred = credentials.Certificate('path/to/serviceAccountKey.json')
firebase_admin.initialize_app(cred)
# Or, for multiple apps:
# firebase_admin.initialize_app(cred, name='my_other_app')
```Import the specific sub-module you intend to use:
```python
import firebase_admin
from firebase_admin import credentials, firestore, auth
# Correct usage after import:
# db = firestore.client()
# user = auth.get_user('some_uid')
```Ensure the `GOOGLE_APPLICATION_CREDENTIALS` environment variable is set to the path of your service account JSON file, or explicitly provide the credentials when initializing the app:
```python
import firebase_admin
from firebase_admin import credentials
import os
# Option 1: Using GOOGLE_APPLICATION_CREDENTIALS env var (recommended for deployment)
# os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = '/path/to/serviceAccountKey.json'
# firebase_admin.initialize_app()
# Option 2: Explicitly providing credentials
cred = credentials.Certificate('path/to/serviceAccountKey.json')
firebase_admin.initialize_app(cred)
```