Registry / gcp / firebase-admin

firebase-admin

JSON →
library7.5.0pypypi✓ verified 26d ago

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-admin
INSTALL
IMPORT
SIG · FIREBASE-ADMIN
F
firebase-admin
gcppythonv7.5.0
Install
7.4s avg
Import
875ms
Disk
84MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v7.5.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.896s · 84.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 7.4s · import 0.854s · 84MB
84MB installed
● package 84MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

firebase_admin
import firebase_admin
credentials
from firebase_admin import credentials
firestore
from firebase_admin import firestore
auth
from firebase_admin import auth
storage
from firebase_admin import storage
messaging
from firebase_admin import messaging

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.

import os import firebase_admin from firebase_admin import credentials, firestore # Best practice: store service account key in an environment variable # and load it, or use Application Default Credentials on Google Cloud. # Replace 'path/to/your/serviceAccountKey.json' with actual path if not using env var. SERVICE_ACCOUNT_KEY_PATH = os.environ.get('FIREBASE_SERVICE_ACCOUNT_KEY_PATH', '') if SERVICE_ACCOUNT_KEY_PATH: cred = credentials.Certificate(SERVICE_ACCOUNT_KEY_PATH) else: # Fallback for Google Cloud environments where ADC are available # or if you prefer not to use a file directly for local testing cred = credentials.ApplicationDefault() # Initialize the app firebase_admin.initialize_app(cred, { 'projectId': os.environ.get('FIREBASE_PROJECT_ID', 'your-project-id'), 'databaseURL': os.environ.get('FIREBASE_DATABASE_URL', 'https://your-project-id.firebaseio.com') }) db = firestore.client() # Add data to Firestore doc_ref = db.collection('users').document('alovelace') doc_ref.set({ 'first': 'Ada', 'last': 'Lovelace', 'born': 1815 }) print(f"Added document with ID: {doc_ref.id}") # Read data from Firestore users_ref = db.collection('users') docs = users_ref.stream() print("\nAll users:") for doc in docs: print(f"{doc.id} => {doc.to_dict()}") # Clean up (optional, for demonstration purposes) # firebase_admin.delete_app(firebase_admin.get_app())
Debug
Known issues
breakingVersion 7.0.0 dropped support for Python 3.7 and 3.8. Python 3.9 support is deprecated; developers are strongly advised to use Python 3.10 or higher.
fix
Upgrade your Python environment to 3.10 or newer.
affects: >=7.0.0
breakingIn version 7.0.0, the `send_all()` and `send_multicast()` FCM APIs were removed.
fix
Migrate to `send_each()` and `send_each_for_multicast()` or their asynchronous counterparts `send_each_async()` and `send_each_for_multicast_async()`.
affects: >=7.0.0
breakingThe dependency on `google-api-python-client` was removed in v7.0.0, significantly reducing the SDK's bundle size. While this generally improves performance, ensure your project does not implicitly rely on this dependency.
fix
No direct fix required for `firebase-admin` itself, but review your project's `requirements.txt` if you previously relied on this transitive dependency.
affects: >=7.0.0
deprecatedThe `ActionCodeSettings.dynamic_link_domain` parameter was deprecated in v7.1.0 in favor of `link_domain` for customizing Firebase Hosting domains in email action flows.
fix
Update `ActionCodeSettings` to use the `link_domain` parameter instead of `dynamic_link_domain`.
affects: >=7.1.0
gotchaThe Python Admin SDK for Firebase Realtime Database does not support real-time event listeners. All data retrieval operations are blocking.
fix
If real-time updates are critical, consider alternative SDKs (e.g., Node.js, Java) or implement a polling mechanism on the Python backend.
affects: *
gotchaService account JSON key files contain sensitive credentials. Never commit them directly to version control.
fix
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.
affects: *
gotchaThe library failed to find default credentials (Application Default Credentials). This typically occurs when running on environments without Google Cloud metadata or without explicitly configured `GOOGLE_APPLICATION_CREDENTIALS`.
fix
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.
affects: *
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'firebase_admin'
The `firebase-admin` package is either not installed, installed in a different Python environment than the one being used, or the Python interpreter cannot find it.
fix
Ensure `firebase-admin` is installed in the correct environment by running: `pip install firebase-admin` or `pip3 install firebase-admin`.
ValueError: The default Firebase app already exists.
The `firebase_admin.initialize_app()` function was called more than once without providing a unique name for each app instance. In most applications, it should only be called once.
fix
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')
```
AttributeError: module 'firebase_admin' has no attribute 'firestore'
Sub-modules like `firestore`, `auth`, `storage`, or `db` must be explicitly imported from `firebase_admin` before they can be accessed.
fix
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')
```
Error: Could not load the default credentials.
The Firebase Admin SDK could not find valid credentials to authenticate with Google Cloud services. This often means the `GOOGLE_APPLICATION_CREDENTIALS` environment variable is not set or points to an invalid service account key file, or the service account key provided to `initialize_app` is incorrect.
fix
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)
```
Upgrade
Version history
7.5.0latest on PyPI · released Jul 2, 2026
Audit
Dependencies
cachecontrolrequiredCaching HTTP responses
google-api-core[grpc]requiredCore Google API client library, used for gRPC communication (not on PyPy)
google-cloud-firestorerequiredClient library for Cloud Firestore (not on PyPy)
google-cloud-storagerequiredClient library for Cloud Storage
pyjwt[crypto]requiredJSON Web Token implementation for authentication
httpx[http2]requiredHTTP client for making requests
Agent activity
43 hits · last 30 days
node
36
OpenAI (training)
1
Resources
firebase-admin — pip install firebase-admin · libregistry