Standard library overview

The Workflows standard library includes modules and frequently used functions, such as for data type and format conversions. 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.

Data type functions

The following conversion functions are supported:

  • 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.

The following functions operate on lists, maps, and strings:

  • in(): Checks whether a given key is present in a map. See Check existence of a key in a 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. Accepts an attribute of type string, list, or map and returns an integer.
    • string: Returns the number of characters in the string.
    • list: Returns the number of elements in the list.
    • map: Returns the number of key-value entries stored in the map.

Random number generation

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 Function to generate a number and call the Cloud Function from your workflow.

Module: base64

Base64 encoding/decoding.

Functions
decode Decodes given Base64-encoded string to bytes.
encode Encodes given bytes to Base64 text.

Module: errors

Constructors for commonly used exceptions.

Functions
index_error Returns a dictionary object with an IndexError tag.
key_error Returns a dictionary object with a KeyError tag.
not_implemented_error Returns a dictionary object with a NotImplementedError tag.
recursion_error Returns a dictionary object with a RecursionError tag.
resource_limit_error Returns a dictionary object with a ResourceLimitError tag.
system_error Returns a dictionary object with a SystemError tag.
timeout_error Returns a dictionary object with a TimeoutError tag.
type_error Returns a dictionary object with a TypeError tag.
value_error Returns a dictionary object with a ValueError tag.
zero_division_error Returns a dictionary object with a ZeroDivisionError tag.

Module: events

Events support.

Functions
await_callback Waits for a callback to be received at the given endpoint.
create_callback_endpoint Creates a callback endpoint expecting the specified HTTP method.

Module: experimental.executions

Execution management.

Functions
execution_error Raised when a Workflow Execution finishes with an error or gets cancelled.
map Starts workflow executions and waits for all of them to finish.
run Starts a workflow execution and waits for it to finish.

Module: http

HTTP/S request support.

Functions
auth_error Returns a map object with an AuthError tag.
connection_error Raised when an HTTP request fails due to a connection error.
default_retry_predicate Simple default retry predicate for idempotent targets.
default_retry_predicate_non_idempotent Simple default retry predicate for non-idempotent targets.
delete Sends an HTTP DELETE request to the specified URL.
get Sends an HTTP GET request to the specified URL.
http_error Raised when an HTTP request fails with an HTTP error status.
patch Sends an HTTP PATCH request to the specified URL.
post Sends an HTTP POST request to the specified URL.
put Sends an HTTP PUT request to the specified URL.
request Sends an HTTP request.
Objects
default_retry Simple default retry policy for idempotent targets.
default_retry_non_idempotent Simple default retry policy for non-idempotent targets.

Module: json

JSON encoding/decoding.

Functions
decode Decodes given JSON bytes (assuming UTF-8), or a string, into an object.
encode Encodes given input object to JSON bytes, using UTF-8 charset.
encode_to_string Encodes given object to a JSON string.

Module: list

List utility.

Functions
concat Creates a copy of a list with a new element concatenated at the end.

Module: retry

Support for retries.

Functions
always Convenience retry condition that retries on any error.
never Convenience retry condition that retries on no error at all.
Objects
default_backoff Simple default truncated exponential backoff policy.

Module: sys

Common system interface, with platform-dependent implementation.

Functions
get_env Retrieves the value of the specified environment variable.
log Writes one of data, text, or json to the log at specified severity.
now Returns wall time, as a floating-point number of seconds since Epoch.
sleep Suspends execution for the given number of seconds.
sleep_until Suspends execution until the given time.

Module: text

Text processing.

To concatenate a string, see Strings.

Functions
decode Decodes given data to string, assuming the specified character set.
encode Encodes given text to bytes, using the specified character set.
find_all Finds the index of all instances of a substring in a string.
find_all_regex Finds all matches of a regular expression in a string.
match_regex Reports whether a string contains a match of a regular expression.
replace_all Replaces all instances of a substring with a new string.
replace_all_regex Replaces all matches of a regular expression with a new string.
split Splits the source string into a list of all substrings between each instance of the separator.
substring Extracts the substring between two indexes of a source string.
to_lower Returns a string with all Unicode letters mapped to their lowercase.
to_upper Returns a string with all Unicode letters mapped to their uppercase.

Module: time

Time-related utility functions.

Functions
format Formats the given timestamp as a human-readable string.
parse Parses given ISO 8601-compatible string into a timestamp.

Module: urlencode

Encodes given input to a url-encoded string.

Functions
encode Encodes given input object to a string, using UTF-8 charset.