Client
Description
The Client enables usage of the JellyFaaS function library.
Most methods are dependant on the Client instance's internal state and must only be called in increasing order of "call sequence" (see below).
Additionally, some methods are marked as "required". These methods must be called to invoke a minimal JellyFaaS function.
For example, neither set_function_body() nor set_function_query_params() may be called before:
Client()set_version()(optionally)lookup_function()
Methods
| Return | Method | Call Sequence |
|---|---|---|
| Client | Client(config: Config) | 1(Required) |
| Client | set_version(version: int) | 2 |
| Client | lookup_function(function_id: str) | 3(Required) |
| Client | set_function_body(query_params: Dict[str, str]) | 4 |
| Client | set_function_query_params(query_params: dict) | 4 |
| Client | invoke(query_params: dict) | 5(Required) |
| Client | get_status_code(query_params: dict) | 6 |
Method Descriptions
Client(config: Config) -> Client
Raises
JellyFaasException
Clientconstructor. The client saves a reference toconfig, which contains your Secret key, handles authentication, and miscellaneous configuration. Ifconfigis invalid, raisesJellyFaasException
set_version(version: int) -> Client
Raises
JellyFaasExceptionSets the version to be used by any following calls to
lookup_function(). This state is cleared upon any call toclear().versionmust be a positive (non-zero) integer. Ifversionis invalid, raisesJellyFaasException.Note
If
set_version()is not called,lookup_function()will default to the newest version. This means your code may break on future releases of any used functions. It is highly recommended to explicitlyset_verion()first, to avoid this.
lookup_function(function_id: str) -> Client
Raises
JellyFaasExceptionRequests the details of the JellyFaaS function with ID specified by
function_idand optionally version specified byset_version(). If version is not specified, defaults to the newest version.If successful, sets the function as the
Client's active function. This will also clear any data set byset_function_body()orset_function_query_params().If unsuccessful, raises
JellyFaasException. This may be due to an invalidfunction_idor version.
set_function_body(body, do_validation: bool = True) -> Client
Raises
JellyFaasExceptionset_function_body is used to pass data to a JellyFaaS function. Specifically, it is used to set the invocation's underlying HTTP request body.
Depending on the function's defined input, set_function_body will expect and validate against different types of data:
a. JSON
set_function_body expects
bodyto be a dict or JSON-serializable class instance (extending from Pydantic BaseModel)b. FILE
set_function_body expects
bodyto be abytesobject.By default, set_function_body will validate your input matches the function schema, ensuring your request is expected to succeed before actually invoking the function. The behaviour can be disabled by setting
do_validation= False
set_function_query_params(query_params: Dict[str, str], do_validation = True) -> Client
Raises
JellyFaasExceptionset_function_query_params is used to pass data to a JellyFaaS function. Specifically, it is used to set the invocation's underlying HTTP request query parameters. set_function_query_params expects
bodyto be a flat dict ofstrkeys and values.By default, set_function_query_params will validate your input matches the function schema, ensuring your request is expected to succeed before actually invoking the function. The behavior can be disabled by setting
do_validation= False
invoke(outputClass: Type = None) -> (Client, response)
Raises
JellyFaasExceptionCalls the JellyFaaS function, with any inputs set by set_function_body and set_function_query_params. If an outputType is passed,
invokewill attempt to cast the response to a new instance of the specified class.
get_status_code() -> Client
Raises
JellyFaasExceptionReturns the HTTP status code returned with the last call of
invoke()