Firebase Admin Python SDK enables server-side Python developers to integrate Firebase services into their applications from privileged environments.
—
Firebase project management for creating and managing Android and iOS app configurations within Firebase projects. Provides comprehensive app lifecycle management and configuration capabilities.
Create and retrieve Android and iOS app instances within Firebase projects with complete configuration management.
def android_app(app_id, app=None):
"""
Get an AndroidApp instance for the specified app ID.
Args:
app_id: Android app ID string
app: Firebase app instance (optional)
Returns:
AndroidApp: Android app instance for management operations
Raises:
NotFoundError: If the app doesn't exist
"""
def ios_app(app_id, app=None):
"""
Get an IOSApp instance for the specified app ID.
Args:
app_id: iOS app ID string
app: Firebase app instance (optional)
Returns:
IOSApp: iOS app instance for management operations
Raises:
NotFoundError: If the app doesn't exist
"""Create new Android and iOS applications in Firebase projects with initial configuration.
def create_android_app(package_name, display_name=None, app=None):
"""
Create a new Android app in the Firebase project.
Args:
package_name: Android package name (e.g., 'com.example.app')
display_name: Human-readable app name (optional)
app: Firebase app instance (optional)
Returns:
AndroidApp: Newly created Android app instance
Raises:
AlreadyExistsError: If an app with the package name already exists
InvalidArgumentError: If the package name is invalid
"""
def create_ios_app(bundle_id, display_name=None, app=None):
"""
Create a new iOS app in the Firebase project.
Args:
bundle_id: iOS bundle identifier (e.g., 'com.example.app')
display_name: Human-readable app name (optional)
app: Firebase app instance (optional)
Returns:
IOSApp: Newly created iOS app instance
Raises:
AlreadyExistsError: If an app with the bundle ID already exists
InvalidArgumentError: If the bundle ID is invalid
"""List all Android and iOS applications in the Firebase project.
def list_android_apps(app=None):
"""
List all Android apps in the project.
Args:
app: Firebase app instance (optional)
Returns:
list[AndroidApp]: List of AndroidApp instances in the project
"""
def list_ios_apps(app=None):
"""
List all iOS apps in the project.
Args:
app: Firebase app instance (optional)
Returns:
list[IOSApp]: List of IOSApp instances in the project
"""class AndroidApp:
"""Represents an Android app in a Firebase project."""
@property
def app_id(self):
"""The Firebase app ID."""
@property
def display_name(self):
"""The human-readable display name."""
@property
def project_id(self):
"""The Firebase project ID."""
@property
def package_name(self):
"""The Android package name."""
def get_metadata(self):
"""
Get the app's metadata.
Returns:
AndroidAppMetadata: Metadata for the Android app
"""
def set_display_name(self, new_display_name):
"""
Set the display name for the app.
Args:
new_display_name: New display name string
"""
def get_config(self):
"""
Get the configuration file content for the app.
Returns:
bytes: Content of the google-services.json file
"""
def get_sha_certificates(self):
"""
Get the SHA certificates for the app.
Returns:
list[SHACertificate]: List of SHA certificates
"""
def add_sha_certificate(self, certificate):
"""
Add a SHA certificate to the app.
Args:
certificate: SHACertificate instance to add
Returns:
SHACertificate: The added certificate with server-assigned name
"""
def delete_sha_certificate(self, certificate_name):
"""
Delete a SHA certificate from the app.
Args:
certificate_name: Name of the certificate to delete
"""
class AndroidAppMetadata:
"""Metadata for an Android app."""
@property
def display_name(self):
"""The display name of the app."""
@property
def app_id(self):
"""The Firebase app ID."""
@property
def package_name(self):
"""The Android package name."""
@property
def project_id(self):
"""The Firebase project ID."""
class SHACertificate:
"""SHA certificate for Android app signing."""
def __init__(self, sha_hash, cert_type=None):
"""
Initialize SHA certificate.
Args:
sha_hash: SHA fingerprint string
cert_type: Certificate type ('SHA_1' or 'SHA_256')
"""
@property
def name(self):
"""The server-assigned certificate name."""
@property
def sha_hash(self):
"""The SHA fingerprint."""
@property
def cert_type(self):
"""The certificate type."""class IOSApp:
"""Represents an iOS app in a Firebase project."""
@property
def app_id(self):
"""The Firebase app ID."""
@property
def display_name(self):
"""The human-readable display name."""
@property
def project_id(self):
"""The Firebase project ID."""
@property
def bundle_id(self):
"""The iOS bundle identifier."""
def get_metadata(self):
"""
Get the app's metadata.
Returns:
IOSAppMetadata: Metadata for the iOS app
"""
def set_display_name(self, new_display_name):
"""
Set the display name for the app.
Args:
new_display_name: New display name string
"""
def get_config(self):
"""
Get the configuration file content for the app.
Returns:
bytes: Content of the GoogleService-Info.plist file
"""
class IOSAppMetadata:
"""Metadata for an iOS app."""
@property
def display_name(self):
"""The display name of the app."""
@property
def app_id(self):
"""The Firebase app ID."""
@property
def bundle_id(self):
"""The iOS bundle identifier."""
@property
def project_id(self):
"""The Firebase project ID."""from firebase_admin import project_management
# Create a new Android app
android_app = project_management.create_android_app(
package_name='com.example.myapp',
display_name='My Android App'
)
print(f'Created Android app: {android_app.app_id}')
print(f'Package name: {android_app.package_name}')
# Get app metadata
metadata = android_app.get_metadata()
print(f'Display name: {metadata.display_name}')
print(f'Project ID: {metadata.project_id}')
# Update display name
android_app.set_display_name('My Updated Android App')
# Download configuration file
config_data = android_app.get_config()
with open('google-services.json', 'wb') as f:
f.write(config_data)# Add SHA certificate for app signing
sha_cert = project_management.SHACertificate(
sha_hash='AA:BB:CC:DD:EE:FF:00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD',
cert_type='SHA_1'
)
added_cert = android_app.add_sha_certificate(sha_cert)
print(f'Added certificate: {added_cert.name}')
# List all SHA certificates
certificates = android_app.get_sha_certificates()
for cert in certificates:
print(f'Certificate: {cert.sha_hash} ({cert.cert_type})')
# Delete a certificate
android_app.delete_sha_certificate(added_cert.name)# Create a new iOS app
ios_app = project_management.create_ios_app(
bundle_id='com.example.myapp',
display_name='My iOS App'
)
print(f'Created iOS app: {ios_app.app_id}')
print(f'Bundle ID: {ios_app.bundle_id}')
# Get app metadata
metadata = ios_app.get_metadata()
print(f'Display name: {metadata.display_name}')
# Update display name
ios_app.set_display_name('My Updated iOS App')
# Download configuration file
config_data = ios_app.get_config()
with open('GoogleService-Info.plist', 'wb') as f:
f.write(config_data)# List all Android apps in the project
android_apps = project_management.list_android_apps()
print(f'Android apps in project: {len(android_apps)}')
for app in android_apps:
print(f' {app.display_name} (ID: {app.app_id})')
print(f' Package: {app.package_name}')
# List all iOS apps in the project
ios_apps = project_management.list_ios_apps()
print(f'iOS apps in project: {len(ios_apps)}')
for app in ios_apps:
print(f' {app.display_name} (ID: {app.app_id})')
print(f' Bundle ID: {app.bundle_id}')# Get existing apps by ID
existing_android = project_management.android_app('1:123456789:android:abcdef123456')
existing_ios = project_management.ios_app('1:123456789:ios:abcdef123456')
print(f'Android app: {existing_android.display_name}')
print(f'iOS app: {existing_ios.display_name}')# Create multiple apps
android_apps_to_create = [
{'package': 'com.example.app1', 'name': 'App One'},
{'package': 'com.example.app2', 'name': 'App Two'},
{'package': 'com.example.app3', 'name': 'App Three'}
]
created_android_apps = []
for app_config in android_apps_to_create:
try:
app = project_management.create_android_app(
package_name=app_config['package'],
display_name=app_config['name']
)
created_android_apps.append(app)
print(f'Created: {app.display_name}')
except Exception as e:
print(f'Failed to create {app_config["name"]}: {e}')
# Download configuration files for all apps
for i, app in enumerate(created_android_apps):
config_data = app.get_config()
filename = f'google-services-{i+1}.json'
with open(filename, 'wb') as f:
f.write(config_data)
print(f'Downloaded config for {app.display_name} to {filename}')# Add the same certificate to multiple Android apps
sha_certificate = project_management.SHACertificate(
sha_hash='11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF:00:11:22:33:44',
cert_type='SHA_256'
)
android_apps = project_management.list_android_apps()
for app in android_apps:
try:
app.add_sha_certificate(sha_certificate)
print(f'Added certificate to {app.display_name}')
except Exception as e:
print(f'Failed to add certificate to {app.display_name}: {e}')import os
from datetime import datetime
def backup_config_files():
"""Backup all app configuration files."""
timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
backup_dir = f'firebase_configs_{timestamp}'
os.makedirs(backup_dir, exist_ok=True)
# Backup Android configs
android_apps = project_management.list_android_apps()
for i, app in enumerate(android_apps):
config_data = app.get_config()
filename = f'{backup_dir}/android_{app.app_id}_google-services.json'
with open(filename, 'wb') as f:
f.write(config_data)
# Backup iOS configs
ios_apps = project_management.list_ios_apps()
for i, app in enumerate(ios_apps):
config_data = app.get_config()
filename = f'{backup_dir}/ios_{app.app_id}_GoogleService-Info.plist'
with open(filename, 'wb') as f:
f.write(config_data)
print(f'Backed up configs to {backup_dir}')
backup_config_files()from firebase_admin.exceptions import NotFoundError, AlreadyExistsError, InvalidArgumentError
try:
# Attempt to create app with existing package name
app = project_management.create_android_app(
package_name='com.existing.app',
display_name='Duplicate App'
)
except AlreadyExistsError:
print('App with this package name already exists')
# Get existing app instead
existing_apps = project_management.list_android_apps()
for existing_app in existing_apps:
if existing_app.package_name == 'com.existing.app':
app = existing_app
break
try:
# Attempt to get non-existent app
app = project_management.android_app('invalid-app-id')
except NotFoundError:
print('App not found')
try:
# Invalid package name
app = project_management.create_android_app(
package_name='invalid-package-name',
display_name='Invalid App'
)
except InvalidArgumentError as e:
print(f'Invalid package name: {e}')class AndroidApp:
"""Represents an Android app in a Firebase project."""
@property
def app_id(self):
"""The Firebase app ID."""
@property
def display_name(self):
"""The human-readable display name."""
@property
def package_name(self):
"""The Android package name."""
class IOSApp:
"""Represents an iOS app in a Firebase project."""
@property
def app_id(self):
"""The Firebase app ID."""
@property
def display_name(self):
"""The human-readable display name."""
@property
def bundle_id(self):
"""The iOS bundle identifier."""
class AndroidAppMetadata:
"""Metadata for an Android app."""
@property
def display_name(self):
"""The display name of the app."""
@property
def app_id(self):
"""The Firebase app ID."""
@property
def package_name(self):
"""The Android package name."""
class IOSAppMetadata:
"""Metadata for an iOS app."""
@property
def display_name(self):
"""The display name of the app."""
@property
def app_id(self):
"""The Firebase app ID."""
@property
def bundle_id(self):
"""The iOS bundle identifier."""
class SHACertificate:
"""SHA certificate for Android app signing."""
def __init__(self, sha_hash, cert_type=None):
"""Initialize SHA certificate."""
@property
def name(self):
"""The server-assigned certificate name."""
@property
def sha_hash(self):
"""The SHA fingerprint."""
@property
def cert_type(self):
"""The certificate type ('SHA_1' or 'SHA_256')."""Install with Tessl CLI
npx tessl i tessl/pypi-firebase-admin