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_intervalFunctionsError(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 |
FunctionsError |
An error from a function call. |
HTTPSCallable |
One callable function. Get it with |
Functions |
Cloud Functions for one region (or custom domain). Get it with |
Attributes:
| Name | Type | Description |
|---|---|---|
FUNCTIONS_ERROR_DOMAIN |
Final
|
The |
FUNCTIONS_ERROR_DETAILS_KEY |
Final
|
The |
CallCallback |
|
FUNCTIONS_ERROR_DOMAIN
module-attribute
¶
The error.domain of errors from function calls.
FUNCTIONS_ERROR_DETAILS_KEY
module-attribute
¶
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 |
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
¶
No answer within HTTPSCallable.timeout_interval.
NOT_FOUND
class-attribute
instance-attribute
¶
No function with that name (or URL, or region).
INTERNAL
class-attribute
instance-attribute
¶
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 |
details |
Any
|
What the function attached to its |
HTTPSCallable
¶
HTTPSCallable(callable_: ObjCObject)
One callable function. Get it with Functions.https_callable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
callable_
|
ObjCObject
|
the native |
required |
Methods:
| Name | Description |
|---|---|
call |
Call the function. |
Attributes:
| Name | Type | Description |
|---|---|---|
timeout_interval |
float
|
Seconds before a call fails with |
timeout_interval
property
writable
¶
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 |
required |
data
|
Any
|
what to send: JSON-like Python values (dict, list, tuple,
str, number, bool, |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
|
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 |
required |
Methods:
| Name | Description |
|---|---|
functions |
The shared |
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 |
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
|
None
|
custom_domain
|
str | None
|
a custom domain the functions are served from (Firebase
Hosting rewrites), for example |
None
|
Returns:
| Type | Description |
|---|---|
Functions
|
The same |
Raises:
| Type | Description |
|---|---|
ValueError
|
both |
use_emulator
¶
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'
|
port
|
int
|
the emulator's port ( |
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 |
required |
require_limited_use_app_check_tokens
|
bool
|
send a single-use App Check
token, for functions with |
False
|
Returns:
| Type | Description |
|---|---|
HTTPSCallable
|
An |
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 |