or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

app-management.mdauthentication.mdfirestore.mdfunctions.mdindex.mdmachine-learning.mdmessaging.mdproject-management.mdrealtime-database.mdremote-config.mdstorage.mdtenant-management.md
tile.json

tessl/pypi-firebase-admin

Firebase Admin Python SDK enables server-side Python developers to integrate Firebase services into their applications from privileged environments.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/firebase-admin@7.1.x

To install, run

npx @tessl/cli install tessl/pypi-firebase-admin@7.1.0

index.mddocs/

Firebase Admin Python SDK

The Firebase Admin Python SDK enables server-side (backend) Python developers to integrate Firebase services into their applications and services from privileged environments like servers or cloud platforms. It provides comprehensive access to Firebase Authentication, Cloud Firestore, Realtime Database, Cloud Messaging, Cloud Storage, Remote Config, Cloud Functions, App Check, Machine Learning, and Project Management APIs.

Package Information

  • Package Name: firebase-admin
  • Language: Python 3.9+
  • Installation: pip install firebase-admin

Core Imports

import firebase_admin
from firebase_admin import credentials

Common service imports:

from firebase_admin import auth
from firebase_admin import firestore
from firebase_admin import db
from firebase_admin import messaging
from firebase_admin import storage
from firebase_admin import tenant_mgt

Basic Usage

import firebase_admin
from firebase_admin import credentials
from firebase_admin import auth

# Initialize the SDK with a service account
cred = credentials.Certificate("path/to/serviceAccountKey.json")
firebase_admin.initialize_app(cred, {
    'databaseURL': 'https://your-project-default-rtdb.firebaseio.com/',
    'storageBucket': 'your-project.appspot.com'
})

# Use Firebase Authentication
user = auth.get_user('user-uid')
print(f'Successfully fetched user data: {user.display_name}')

# Create custom token
custom_token = auth.create_custom_token('user-uid')
print(f'Custom token: {custom_token.decode()}')

Architecture

Firebase Admin SDK follows a service-oriented architecture:

  • App Management: Central application instances managing credentials and configuration
  • Service Modules: Individual modules for each Firebase service (auth, firestore, db, etc.)
  • Credential System: Multiple authentication methods including service accounts and application default credentials
  • Error Handling: Comprehensive exception hierarchy for different error conditions

Each service module provides both high-level convenience functions and access to underlying client objects for advanced operations.

Capabilities

App Management

Core application lifecycle management including initialization, configuration, and cleanup. Manages credentials and provides the foundation for all Firebase service access.

def initialize_app(credential=None, options=None, name='[DEFAULT]'):
    """
    Initializes and returns a new App instance.
    
    Args:
        credential: A credential object (optional)
        options: Configuration options dict (optional)
        name: Name of the app (optional)
    
    Returns:
        App: A newly initialized App instance
    """

def get_app(name='[DEFAULT]'):
    """
    Retrieves an App instance by name.
    
    Args:
        name: Name of the App instance to retrieve
        
    Returns:
        App: An App instance with the given name
    """

def delete_app(app):
    """
    Gracefully deletes an App instance.
    
    Args:
        app: The app instance to be deleted
    """

App Management

Authentication and User Management

Comprehensive user authentication and management capabilities including custom token generation, ID token verification, user CRUD operations, and multi-tenant authentication.

def create_custom_token(uid, developer_claims=None, app=None):
    """Create a custom token for the given UID."""

def verify_id_token(id_token, app=None, check_revoked=False, clock_skew_seconds=0):
    """Verify a Firebase ID token."""

def get_user(uid, app=None):
    """Get a user by UID."""

def create_user(**kwargs):
    """Create a new user."""

def update_user(uid, **kwargs):
    """Update an existing user."""

def delete_user(uid, app=None):
    """Delete a user."""

Authentication

Cloud Firestore

Complete Cloud Firestore database integration providing access to the full Google Cloud Firestore client with document and collection operations, queries, transactions, and batch operations.

def client(app=None, database_id=None):
    """
    Return a client for interacting with the Cloud Firestore database.
    
    Args:
        app: Firebase app instance (optional)
        database_id: Database ID (optional)
        
    Returns:
        google.cloud.firestore.Client: Firestore client instance
    """

Cloud Firestore

Realtime Database

Firebase Realtime Database operations including data reading, writing, querying, transactions, and real-time listeners for JSON tree-structured data.

def reference(path='/', app=None, url=None):
    """
    Return a database reference for the specified path.
    
    Args:
        path: Database path (default: '/')
        app: Firebase app instance (optional)
        url: Database URL (optional)
        
    Returns:
        Reference: Database reference instance
    """

Realtime Database

Cloud Messaging

Firebase Cloud Messaging (FCM) for sending push notifications and managing topic subscriptions across Android, iOS, and web platforms.

def send(message, dry_run=False, app=None):
    """Send a message to Firebase Cloud Messaging."""

def send_each(messages, dry_run=False, app=None):
    """Send multiple messages to Firebase Cloud Messaging."""

def subscribe_to_topic(tokens, topic, app=None):
    """Subscribe registration tokens to a topic."""

def unsubscribe_from_topic(tokens, topic, app=None):
    """Unsubscribe registration tokens from a topic."""

Cloud Messaging

Cloud Storage

Firebase Cloud Storage integration providing access to Google Cloud Storage buckets for file upload, download, and management operations.

def bucket(name=None, app=None):
    """
    Return a handle to a Cloud Storage bucket.
    
    Args:
        name: Bucket name (optional, uses default from config)
        app: Firebase app instance (optional)
        
    Returns:
        google.cloud.storage.Bucket: Storage bucket instance
    """

Cloud Storage

Cloud Functions

Firebase Cloud Functions integration for enqueueing tasks in Cloud Task queues associated with callable functions.

def task_queue(function_name, extension_id=None, app=None):
    """
    Get a TaskQueue instance for the specified function.
    
    Args:
        function_name: Name of the Cloud Function
        extension_id: Extension ID (optional)
        app: Firebase app instance (optional)
        
    Returns:
        TaskQueue: Task queue instance
    """

Cloud Functions

Machine Learning

Firebase ML model management for deploying and managing custom machine learning models in Firebase projects.

def create_model(model, app=None):
    """Create a new ML model in Firebase."""

def get_model(model_id, app=None):
    """Get an ML model by ID."""

def list_models(list_filter=None, page_size=None, page_token=None, app=None):
    """List ML models in the project."""

Machine Learning

Remote Config

Firebase Remote Config server-side template management for dynamic app configuration without requiring app updates.

class ServerTemplate:
    """Server-side Remote Config template management."""
    
    def evaluate(self, context=None):
        """Evaluate the template with optional context."""
        
    def load(self):
        """Load the current Remote Config template."""

Remote Config

Project Management

Firebase project management for creating and managing Android and iOS app configurations within Firebase projects.

def create_android_app(package_name, display_name=None, app=None):
    """Create a new Android app in the Firebase project."""

def create_ios_app(bundle_id, display_name=None, app=None):
    """Create a new iOS app in the Firebase project."""

def list_android_apps(app=None):
    """List all Android apps in the project."""

def list_ios_apps(app=None):
    """List all iOS apps in the project."""

Project Management

Tenant Management

Multi-tenant authentication management using Google Cloud Identity Platform (GCIP), enabling isolated authentication environments within a single project.

def auth_for_tenant(tenant_id, app=None):
    """Get an Auth client scoped to a specific tenant."""

def get_tenant(tenant_id, app=None):
    """Get a tenant by ID."""

def create_tenant(display_name, allow_password_sign_up=None, enable_email_link_sign_in=None, app=None):
    """Create a new tenant."""

def update_tenant(tenant_id, display_name=None, allow_password_sign_up=None, enable_email_link_sign_in=None, app=None):
    """Update an existing tenant."""

def delete_tenant(tenant_id, app=None):
    """Delete a tenant."""

def list_tenants(page_token=None, max_results=100, app=None):
    """List tenants with pagination."""

Tenant Management

Types

class App:
    """Firebase application instance."""
    
    @property
    def name(self):
        """The name of this App instance."""
    
    @property
    def credential(self):
        """The credential used to initialize this App."""
    
    @property
    def options(self):
        """The configuration options for this App."""
    
    @property
    def project_id(self):
        """The Google Cloud project ID associated with this App."""

class FirebaseError(Exception):
    """Base exception for all Firebase-related errors."""
    
    def __init__(self, code, message, cause=None, http_response=None):
        """
        Initialize FirebaseError.
        
        Args:
            code: Error code string
            message: Error message
            cause: Underlying cause exception (optional)
            http_response: HTTP response object (optional)
        """
    
    @property
    def code(self):
        """The error code."""
    
    @property
    def cause(self):
        """The underlying cause of this error."""
    
    @property
    def http_response(self):
        """The HTTP response that caused this error."""