CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-firebase-admin

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

Pending
Overview
Eval results
Files

tenant-management.mddocs/

Tenant Management

Multi-tenant authentication management using Google Cloud Identity Platform (GCIP), enabling isolated authentication environments within a single Firebase project. Each tenant provides independent user authentication while sharing the same Firebase project resources.

Capabilities

Tenant-Scoped Authentication

Get Auth client instances scoped to specific tenants for isolated authentication operations.

def auth_for_tenant(tenant_id, app=None):
    """
    Get an Auth Client instance scoped to the given tenant ID.

    Args:
        tenant_id: A tenant ID string
        app: Firebase app instance (optional)

    Returns:
        auth.Client: An Auth client scoped to the specified tenant

    Raises:
        ValueError: If the tenant ID is None, empty or not a string
    """

Tenant Retrieval

Get tenant information by tenant ID.

def get_tenant(tenant_id, app=None):
    """
    Get the tenant corresponding to the given tenant ID.

    Args:
        tenant_id: A tenant ID string
        app: Firebase app instance (optional)

    Returns:
        Tenant: A tenant object

    Raises:
        ValueError: If the tenant ID is None, empty or not a string
        TenantNotFoundError: If no tenant exists by the given ID
        FirebaseError: If an error occurs while retrieving the tenant
    """

Tenant Management

Create, update, and delete tenants with authentication configuration options.

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

    Args:
        display_name: Display name for the new tenant (4-20 characters, letters/digits/hyphens)
        allow_password_sign_up: Whether to enable email sign-in provider (optional)
        enable_email_link_sign_in: Whether to enable email link sign-in (optional)
        app: Firebase app instance (optional)

    Returns:
        Tenant: A tenant object

    Raises:
        ValueError: If any of the given arguments are invalid
        FirebaseError: If an error occurs while creating the 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 with the given options.

    Args:
        tenant_id: ID of the tenant to update
        display_name: Updated display name for the tenant (optional)
        allow_password_sign_up: Whether to enable email sign-in provider (optional)
        enable_email_link_sign_in: Whether to enable email link sign-in (optional)
        app: Firebase app instance (optional)

    Returns:
        Tenant: The updated tenant object

    Raises:
        ValueError: If any of the given arguments are invalid
        TenantNotFoundError: If no tenant exists by the given ID
        FirebaseError: If an error occurs while updating the tenant
    """

def delete_tenant(tenant_id, app=None):
    """
    Delete the tenant corresponding to the given tenant ID.

    Args:
        tenant_id: A tenant ID string
        app: Firebase app instance (optional)

    Raises:
        ValueError: If the tenant ID is None, empty or not a string
        TenantNotFoundError: If no tenant exists by the given ID
        FirebaseError: If an error occurs while deleting the tenant
    """

Tenant Listing

List and paginate through all tenants in the Firebase project.

def list_tenants(page_token=None, max_results=100, app=None):
    """
    Retrieve a page of tenants from a Firebase project.

    Args:
        page_token: Token for paginating results (optional)
        max_results: Maximum number of tenants to return (optional, max 100)
        app: Firebase app instance (optional)

    Returns:
        ListTenantsPage: Page of tenant records with pagination info

    Raises:
        ValueError: If max_results or page_token are invalid
        FirebaseError: If an error occurs while retrieving tenants
    """

Types

class Tenant:
    """Represents a tenant in a multi-tenant application."""
    
    @property
    def tenant_id(self):
        """The tenant ID."""
    
    @property
    def display_name(self):
        """The display name of the tenant."""
    
    @property
    def allow_password_sign_up(self):
        """Whether password sign-up is allowed."""
    
    @property
    def enable_email_link_sign_in(self):
        """Whether email link sign-in is enabled."""

class ListTenantsPage:
    """Page of tenant records with pagination."""
    
    @property
    def tenants(self):
        """List of Tenant instances in this page."""
    
    @property
    def next_page_token(self):
        """Token for the next page (empty string if no more pages)."""
    
    @property
    def has_next_page(self):
        """Whether there are more pages available."""
    
    def get_next_page(self):
        """Get the next page of results."""
    
    def iterate_all(self):
        """Iterator for all tenants starting from this page."""

class TenantNotFoundError(FirebaseError):
    """Error raised when a tenant is not found."""

class TenantIdMismatchError(FirebaseError):
    """Error raised when tenant ID doesn't match the expected value."""

Usage Examples

Basic Tenant Creation and Management

import firebase_admin
from firebase_admin import credentials, tenant_mgt

# Initialize Firebase Admin SDK
cred = credentials.Certificate("path/to/serviceAccountKey.json")
firebase_admin.initialize_app(cred)

# Create a new tenant
tenant = tenant_mgt.create_tenant(
    display_name="my-tenant-1",
    allow_password_sign_up=True,
    enable_email_link_sign_in=False
)

print(f"Created tenant: {tenant.tenant_id}")
print(f"Display name: {tenant.display_name}")

# Get tenant information
retrieved_tenant = tenant_mgt.get_tenant(tenant.tenant_id)
print(f"Retrieved tenant: {retrieved_tenant.display_name}")

# Update tenant
updated_tenant = tenant_mgt.update_tenant(
    tenant.tenant_id,
    display_name="updated-tenant-name",
    enable_email_link_sign_in=True
)

# List all tenants
page = tenant_mgt.list_tenants()
for tenant in page.tenants:
    print(f"Tenant: {tenant.tenant_id} - {tenant.display_name}")

Tenant-Scoped Authentication

from firebase_admin import tenant_mgt, auth

# Get Auth client scoped to a specific tenant
tenant_auth = tenant_mgt.auth_for_tenant("my-tenant-1")

# Use tenant-scoped auth operations
user = tenant_auth.create_user(
    email="user@example.com",
    password="password123"
)

# Create custom token for tenant user
custom_token = tenant_auth.create_custom_token(user.uid)

# All auth operations are scoped to the tenant
tenant_users = tenant_auth.list_users()

Install with Tessl CLI

npx tessl i tessl/pypi-firebase-admin

docs

app-management.md

authentication.md

firestore.md

functions.md

index.md

machine-learning.md

messaging.md

project-management.md

realtime-database.md

remote-config.md

storage.md

tenant-management.md

tile.json