Skip to content

Script Development / Environment Variable DFF.ENV

Environment variables configured in the left sidebar of the Script editor can be read in Script using their IDs.

API

Method Description
DFF.ENV(key, default=None) Reads the environment variable; returns default if it does not exist
DFF.ENV.get(key, default=None) Equivalent to calling DFF.ENV(...) directly
DFF.ENV.keys() Returns the list of IDs of available environment variables
DFF.ENV.ref(key, default=None) Creates a lazy reference for DFF.API parameters that support dynamic values
Example
1
2
3
company_name = DFF.ENV('companyName')
page_size = DFF.ENV('pageSize', default=10)
all_keys = DFF.ENV.keys()

When an environment variable is not found, default is returned; if no default is provided, None is returned. Environment variables of type password are automatically decrypted; when type conversion is configured, the converted Python value is returned. Configuration errors may cause type conversion to throw an exception, so you should provide a default value or fallback logic when reading optional variables.

Example with type fallback
1
2
3
4
5
def get_page_size():
    try:
        return int(DFF.ENV('pageSize', default=10) or 10)
    except Exception:
        return 10

Dynamic Reference

DFF.ENV.ref(...) returns a dynamic reference, not the current environment variable value. The reference is resolved when consuming Func metadata and can be used for the delayed_cron_job, timeout, expires, and queue parameters of DFF.API.

Example
1
2
3
@DFF.API('Dynamic timeout', timeout=DFF.ENV.ref('FUNC_TIMEOUT', default=35))
def dynamic_timeout():
    return 'ok'

Connection addresses, tokens, passwords, and environment-specific configurations should be stored in environment variables first. Do not hard-code them in Script, and do not output sensitive values via print(...) or Func responses.