Standard library overview

The Workflows standard library modules allow you to easily construct arguments for services and process responses. There is no need to import or load libraries in a workflow—library functions work out of the box.

All functions can be called using call steps, but only non-blocking functions can be used inside an expression. For example, HTTP calls, sys.sleep, and sys.log cannot be used inside an expression. For more information, see Blocking calls.

Workflows also includes frequently used functions, such as for data type and format conversions. See Expression helpers.

Generate random identifiers or numbers

You can use uuid.generate to return a random 128‑bit universally unique identifier (UUID) in string form.

You can use sys.now to generate multiple random numbers. (The function returns a floating point number with nanosecond precision.)

  • If you need only one number, use sys.get_env to retrieve the workflow's execution identifier.

  • If a unique ID is needed, you can use string() to convert the number returned from sys.now to a string and combine it with the execution ID; for example, some_execution_id1635892223.4459958.

Optionally, you can use a Cloud Run function to generate a number and call the Cloud Run function from your workflow.

Expression helpers

Built-in expression helper functions.

Conversion functions

Convert values from one data type to another.

Functions
double()Accepts an attribute of type string or integer and returns a double.
int()Accepts an attribute of type string or double and returns an integer.
string()Accepts an attribute of type integer, double, or boolean and returns a string.

Data type functions

Operate on lists, maps, and strings.

Functions
in()Checks whether a given key is present in a list or map.
keys()Accepts an attribute of type map and returns a list of key elements in the map.
len()Computes the length of value according to its type.

Conditional functions

Support conditions within expressions.

Functions
default(val, defaultVal)Returns a value if it is not null; otherwise returns a default value.
if(condition, ifTrue, ifFalse)Evaluates a condition and returns one of two arguments depending on what the condition evaluates to.

Type functions

Return data type.

Functions
get_type(arg)Returns a string indicating the data type of the argument.

Module: base64

Base64 encoding/decoding.

Functions
decodeDecodes given Base64-encoded string to bytes.
encodeEncodes given bytes to Base64 text.

Module: events

Events support.

Functions
await_callbackWaits for a callback to be received at the given endpoint.
create_callback_endpointCreates a callback endpoint expecting the specified HTTP method.

Module: experimental.executions

Execution management.

Instead of using experimental.executions.map to support parallel work, we recommend you execute workflow steps in parallel. If you are already using experimental.executions.map, you can migrate your workflow to use parallel steps.

Functions
execution_errorRaised when a workflow execution finishes with an error or is cancelled.
mapStarts workflow executions and waits for all of them to finish.
runStarts a workflow execution and waits for it to finish.

Module: hash

Common hashing algorithms.

Functions
compute_checksumComputes checksum using a given hashing algorithm.
compute_hmacComputes the hash-based message authentication code (HMAC) for data given a secret key and hashing algorithm.

Module: http

HTTP/S request support.

Functions
default_retry_predicateSimple default retry predicate for idempotent targets.
default_retry_predicate_non_idempotentSimple default retry predicate for non-idempotent targets.
deleteSends an HTTP DELETE request to the specified URL.
getSends an HTTP GET request to the specified URL.
Sends an HTTP request to the specified URL.
postSends an HTTP POST request to the specified URL.
putSends an HTTP PUT request to the specified URL.
requestSends an HTTP request.
Objects
default_retrySimple default retry policy for idempotent targets.
default_retry_non_idempotentSimple default retry policy for non-idempotent targets.

Module: json

JSON encoding/decoding.

Functions
decodeDecodes given JSON bytes (assuming UTF-8), or a string, into an object.
encodeEncodes given input object to JSON bytes, using UTF-8 charset.
encode_to_stringEncodes given object to a JSON string.

Module: list

List utility.

Functions
concatCreates a copy of a list with a new element concatenated at the end.
prependCreates a copy of a list with a new element added to the beginning.

Module: map

Map utility.

Functions
deleteTakes a map, creates a copy of the map, and removes the item with the specified key.
getPerforms a safe lookup on a map, returning null if the key is not found.
mergeTakes two maps, creates a copy of the first map, and adds the items from the second map to the copy.
merge_nestedTakes two maps, creates a copy of the first map, and recursively adds items from the second map to the copy.

Module: math

Math utility.

Functions
absReturns the absolute value of a number.
floorReturns the floor of a number.
maxReturns the maximum of two numbers.
minReturns the minimum of two numbers.

Module: retry

Support for retries.

Functions
alwaysConvenience retry condition that retries on any error.
neverConvenience retry condition that retries on no error at all.
Objects
default_backoffSimple default truncated exponential backoff policy.

Module: sys

Common system interface, with platform-dependent implementation.

Functions
get_envRetrieves the value of the specified environment variable.
logWrites one of data, text, or json to the log at specified severity.
nowReturns Unix time, as a floating-point number.
sleepSuspends execution for the given number of seconds.
sleep_untilSuspends execution until the given time.

Module: text

Text processing.

To concatenate a string, see Strings.

Functions
decodeDecodes given data to string, assuming the specified character set.
encodeEncodes given text to bytes, using the specified character set.
find_allFinds the index of all instances of a substring in a string.
find_all_regexFinds all matches of a regular expression in a string.
match_regexReports whether a string contains a match of a regular expression.
replace_allReplaces all instances of a substring with a new string.
replace_all_regexReplaces all matches of a regular expression with a new string.
splitSplits the source string into a list of all substrings between each instance of the separator.
substringExtracts the substring between two zero-based indexes of a source string.
to_lowerReturns a string with all Unicode letters mapped to their lowercase.
to_upperReturns a string with all Unicode letters mapped to their uppercase.
url_decodeReturns a string with pluses and percent-escaped characters converted to UTF-8.
url_encodeReturns a string with percent-encoded reserved characters, including spaces.
url_encode_plusReturns a string with percent-encoded reserved characters, and spaces replaced by pluses (+).

Module: time

Time-related utility functions.

Functions
formatFormats the given timestamp as a human-readable string.
parseParses the given RFC 3339-compatible string into a timestamp.

Module: uuid

UUID utility.

Functions
generateReturns a random universally unique identifier (UUID).