Skip to content

Cloud Functions reference

At a glance

  • Functions.functions(region=None, custom_domain=None), use_emulator(host, port)
  • https_callable(name, require_limited_use_app_check_tokens=False), https_callable_from_url(url, ...)
  • HTTPSCallable.call(callback, data=None), timeout_interval
  • FunctionsError (code, name, description, details), FunctionsErrorCode

pyios_firebase.functions

Cloud Functions for Firebase: call HTTPS callable functions.

from pyios_firebase.functions import Functions

def on_result(data, error):
    if error is not None:
        print(error.name, error.description, error.details)
        return
    print(data)

Functions.functions().https_callable("addMessage").call(on_result, {"text": "Hello"})

data is what the function returned, as Python values. Auth and App Check tokens are attached by the SDK when those products are in the app.

Streaming callables (stream()) are Swift-only in the Firebase SDK, so they are not available from Python.

Needs the FirebaseFunctions framework.

Classes:

Name Description
FunctionsErrorCode

The error.code values of function call errors (FIRFunctionsErrorCode).

FunctionsError

An error from a function call.

HTTPSCallable

One callable function. Get it with Functions.https_callable.

Functions

Cloud Functions for one region (or custom domain). Get it with

Attributes:

Name Type Description
FUNCTIONS_ERROR_DOMAIN Final

The error.domain of errors from function calls.

FUNCTIONS_ERROR_DETAILS_KEY Final

The userInfo key the SDK uses for an HttpsError's details.

CallCallback

(data, error): the function's return value (None on error), and the error.

FUNCTIONS_ERROR_DOMAIN module-attribute

FUNCTIONS_ERROR_DOMAIN: Final = 'com.firebase.functions'

The error.domain of errors from function calls.

FUNCTIONS_ERROR_DETAILS_KEY module-attribute

FUNCTIONS_ERROR_DETAILS_KEY: Final = 'details'

The userInfo key the SDK uses for an HttpsError's details.

CallCallback module-attribute

CallCallback = Callable[[Any, FunctionsError | None], None]

(data, error): the function's return value (None on error), and the error.

FunctionsErrorCode

The error.code values of function call errors (FIRFunctionsErrorCode).

They match the HttpsError codes a function throws ("invalid-argument" is INVALID_ARGUMENT, and so on).

Attributes:

Name Type Description
DEADLINE_EXCEEDED Final

No answer within HTTPSCallable.timeout_interval.

NOT_FOUND Final

No function with that name (or URL, or region).

INTERNAL Final

The function failed with an unexpected error (or threw a plain Error).

DEADLINE_EXCEEDED class-attribute instance-attribute

DEADLINE_EXCEEDED: Final = 4

No answer within HTTPSCallable.timeout_interval.

NOT_FOUND class-attribute instance-attribute

NOT_FOUND: Final = 5

No function with that name (or URL, or region).

INTERNAL class-attribute instance-attribute

INTERNAL: Final = 13

The function failed with an unexpected error (or threw a plain Error).

FunctionsError

Bases: FirebaseError

An error from a function call.

Attributes:

Name Type Description
name str

The FunctionsErrorCode name of code (for example

details Any

What the function attached to its HttpsError (as Python values), or None.

name instance-attribute

name: str

The FunctionsErrorCode name of code (for example "INVALID_ARGUMENT"), or "" for errors from other domains.

details instance-attribute

details: Any

What the function attached to its HttpsError (as Python values), or None.

HTTPSCallable

HTTPSCallable(callable_: ObjCObject)

One callable function. Get it with Functions.https_callable.

Parameters:

Name Type Description Default
callable_ ObjCObject

the native FIRHTTPSCallable.

required

Methods:

Name Description
call

Call the function.

Attributes:

Name Type Description
timeout_interval float

Seconds before a call fails with DEADLINE_EXCEEDED (default 70).

timeout_interval property writable

timeout_interval: float

Seconds before a call fails with DEADLINE_EXCEEDED (default 70).

call

call(callback: CallCallback, data: Any = None) -> None

Call the function.

Parameters:

Name Type Description Default
callback CallCallback

gets (result, None), or (None, FunctionsError). result is what the function returned, as Python values.

required
data Any

what to send: JSON-like Python values (dict, list, tuple, str, number, bool, None), or nothing.

None

Raises:

Type Description
TypeError

data holds a value JSON cannot carry (for example a datetime, a set, nan or inf). Nothing is sent.

Functions

Functions(functions: ObjCObject)

Cloud Functions for one region (or custom domain). Get it with Functions.functions().

Parameters:

Name Type Description Default
functions ObjCObject

the native FIRFunctions.

required

Methods:

Name Description
functions

The shared Functions for a region or a custom domain.

use_emulator

Send this instance's calls to the local Functions emulator. Call it

https_callable

A callable function, by name.

https_callable_from_url

A callable function, by its full URL (for example a Cloud Run URL).

Attributes:

Name Type Description
native ObjCObject

The FIRFunctions.

native property

native: ObjCObject

The FIRFunctions.

functions classmethod

functions(
    region: str | None = None,
    custom_domain: str | None = None,
) -> Functions

The shared Functions for a region or a custom domain.

Parameters:

Name Type Description Default
region str | None

the region the functions are deployed to, for example "europe-west1". None means us-central1.

None
custom_domain str | None

a custom domain the functions are served from (Firebase Hosting rewrites), for example "https://example.com". Not together with region.

None

Returns:

Type Description
Functions

The same Functions for the same arguments.

Raises:

Type Description
ValueError

both region and custom_domain are given.

use_emulator

use_emulator(
    host: str = "127.0.0.1", port: int = 5001
) -> None

Send this instance's calls to the local Functions emulator. Call it before any call; use it only in development and test builds.

Parameters:

Name Type Description Default
host str

the emulator's host. "127.0.0.1" works in the iOS Simulator; on a device, use the Mac's LAN address.

'127.0.0.1'
port int

the emulator's port (firebase emulators:start uses 5001).

5001

https_callable

https_callable(
    name: str,
    require_limited_use_app_check_tokens: bool = False,
) -> HTTPSCallable

A callable function, by name.

Parameters:

Name Type Description Default
name str

the function's exported name, for example "addMessage".

required
require_limited_use_app_check_tokens bool

send a single-use App Check token, for functions with enforceAppCheck and consumeAppCheckToken (replay protection).

False

Returns:

Type Description
HTTPSCallable

An HTTPSCallable. Run it with call.

https_callable_from_url

https_callable_from_url(
    url: str,
    require_limited_use_app_check_tokens: bool = False,
) -> HTTPSCallable

A callable function, by its full URL (for example a Cloud Run URL).

Parameters:

Name Type Description Default
url str

the function's URL.

required
require_limited_use_app_check_tokens bool

send a single-use App Check token.

False

Returns:

Type Description
HTTPSCallable

An HTTPSCallable.