firebase_functions.db_fn module

Module for Cloud Functions that are triggered by the Firebase Realtime Database.

Classes

Event

class firebase_functions.db_fn.Event(specversion: str, id: str, source: str, type: str, time: datetime, data: T, subject: str | None, firebase_database_host: str, instance: str, reference: str, location: str, params: dict[str, str])

Bases: CloudEvent[T]

A CloudEvent that contains a DataSnapshot or a Change<DataSnapshot>.

firebase_database_host: str

The domain of the database instance.

instance: str

The instance ID portion of the fully qualified resource name.

location: str

The location of the database

params: dict[str, str]

A dict containing the values of the path patterns. Only named capture groups are populated - {key}, {key=*}, {key=**}

reference: str

The database reference path.

Functions

on_value_created

firebase_functions.db_fn.on_value_created(**kwargs) Callable[[Callable[[Event[Any | None]], None]], Callable[[Event[Any | None]], None]]

Event handler that triggers when data is created in Realtime Database.

Example:

@on_value_created(reference="*")
def example(event: Event[object]):
  pass
Parameters:

**kwargs (as firebase_functions.options.DatabaseOptions) -- Database options.

Return type:

typing.Callable [ [ firebase_functions.db_fn.Event [ object ] ], None ] A function that takes a Database Event and returns None.

on_value_deleted

firebase_functions.db_fn.on_value_deleted(**kwargs) Callable[[Callable[[Event[Any | None]], None]], Callable[[Event[Any | None]], None]]

Event handler that triggers when data is deleted in Realtime Database.

Example:

@on_value_deleted(reference="*")
def example(event: Event[object]) -> None:
    pass
Parameters:

**kwargs (as firebase_functions.options.DatabaseOptions) -- Database options.

Return type:

typing.Callable [ [ firebase_functions.db_fn.Event [ object ] ], None ] A function that takes a Database Event and returns None.

on_value_updated

firebase_functions.db_fn.on_value_updated(**kwargs) Callable[[Callable[[Event[Change[Any | None]]], None]], Callable[[Event[Change[Any | None]]], None]]

Event handler that triggers when data is updated in Realtime Database.

Example:

@on_value_updated(reference="*")
def example(event: Event[Change[object]]) -> None:
    pass
Parameters:

**kwargs (as firebase_functions.options.DatabaseOptions) -- Database options.

Return type:

typing.Callable [ [ firebase_functions.db_fn.Event [ firebase_functions.core.Change ] ], None ] A function that takes a Database Event and returns None.

on_value_written

firebase_functions.db_fn.on_value_written(**kwargs) Callable[[Callable[[Event[Change[Any | None]]], None]], Callable[[Event[Change[Any | None]]], None]]

Event handler that triggers when data is created, updated, or deleted in Realtime Database.

Example:

@on_value_written(reference="*")
def example(event: Event[Change[object]]) -> None:
    pass
Parameters:

**kwargs (as firebase_functions.options.DatabaseOptions) -- Database options.

Return type:

typing.Callable [ [ firebase_functions.db_fn.Event [ firebase_functions.core.Change ] ], None ] A function that takes a Database Event and returns None.