ENV

Inherits: Object

A singleton class providing robust environment variable loading, parsing, and management functionalities.

Description

The ENV singleton manages the loading of .env files and integration with system environment variables. It provides a complete toolkit for parsing environment configurations manually, fetching specific data types explicitly with default fallbacks, and pushing environment variables dynamically into OS processes.

Tutorials

Properties

bool

debug

false

Methods

void

auto_config(dir: String = "res://", mode: String = "")

void

bind_env(node: Object, property_map: Dictionary)

void

clear()

Dictionary

config(file: String, override: bool = true)

String

expand_string(text: String)

void

export_json(file: String)

void

generate_example(file: String)

Dictionary

get_all_env() const

Variant

get_env(key: String, default: Variant = null)

Array[String]

get_env_array(key: String, default: Array[String] = [], delimiter: String = ",")

bool

get_env_bool(key: String, default: bool = false)

Color

get_env_color(key: String, default: Color = Color(0, 0, 0, 1))

Dictionary

get_env_dict(key: String, default: Dictionary = {})

Array[String]

get_env_files() const

float

get_env_float(key: String, default: float = 0.0)

Dictionary

get_env_group(prefix: String)

int

get_env_int(key: String, default: int = 0)

Vector2

get_env_vector2(key: String, default: Vector2 = Vector2(0, 0))

Vector3

get_env_vector3(key: String, default: Vector3 = Vector3(0, 0, 0))

Vector4

get_env_vector4(key: String, default: Vector4 = Vector4(0, 0, 0, 0))

Dictionary

get_envs_from_file(file: String)

Dictionary

get_envs_matching(pattern: String)

Array[String]

get_missing_envs(keys: Array[String])

bool

get_prioritize_os_env() const

bool

has_env(key: String)

bool

has_env_file(file: String) const

Dictionary

load_env_file(file: String, override: bool = true)

Dictionary

parse(data: String)

Dictionary

parse_buffer(data: PackedByteArray)

Dictionary

populate(env: Dictionary, override: bool = false)

void

push_to_os_env()

Dictionary

refresh(override: bool = false)

void

remove_env(key: String)

bool

require_envs(keys: Array[String])

void

save(file: String)

void

set_bool_whitelist(true_terms: Array[String], false_terms: Array[String])

void

set_env(key: String, value: Variant)

void

set_prioritize_os_env(prioritize: bool)

void

set_resolver(callable: Callable)


Signals

cleared() 🔗

Signal emitted when all environment variables are cleared.


file_loaded(file: String, env: Dictionary) 🔗

Signal emitted when a file is loaded.


refreshed(env: Dictionary) 🔗

Signal emitted when environment variables are refreshed.


updated(key: String, value: String) 🔗

Signal emitted when an environment variable is updated.


Property Descriptions

bool debug = false 🔗

  • void set_debug(value: bool)

  • bool get_debug()

Controls debug mode.


Method Descriptions

void auto_config(dir: String = "res://", mode: String = "") 🔗

Automatically loads default environment files (e.g., .env) based on the specified search directory and mode string suffix.


void bind_env(node: Object, property_map: Dictionary) 🔗

Binds specific environment keys to a node's properties according to the provided property_map Dictionary.


void clear() 🔗

Clears all internally loaded environment variables from the module memory. Does not affect the operating system's environment variables.


Dictionary config(file: String, override: bool = true) 🔗

Loads environment variables from the specified file. Existing variables in the cache are overridden if override is set to true.


String expand_string(text: String) 🔗

Expands a string by replacing embedded environment variable markers (e.g., ${VAR}) with their corresponding evaluated values.


void export_json(file: String) 🔗

Exports the currently loaded environment variables directly into a specified JSON file format.


void generate_example(file: String) 🔗

Generates an example .env file based on the currently loaded keys, outputting empty templates to the given file path.


Dictionary get_all_env() const 🔗

Retrieves a dictionary containing all currently mapped and loaded environment variables.


Variant get_env(key: String, default: Variant = null) 🔗

Returns the value of the environment variable specified by its key. If it doesn't exist, returns the provided default value.


Array[String] get_env_array(key: String, default: Array[String] = [], delimiter: String = ",") 🔗

Retrieves an Array of Strings from the environment variable using the specified delimiter string to separate the elements.


bool get_env_bool(key: String, default: bool = false) 🔗

Retrieves a boolean value from the environment variable. Evaluates based on the internal true/false string whitelists.


Color get_env_color(key: String, default: Color = Color(0, 0, 0, 1)) 🔗

Retrieves a Color value from the environment variable, parsing a hex string or comma-separated components.


Dictionary get_env_dict(key: String, default: Dictionary = {}) 🔗

Retrieves a Dictionary parsed from a JSON string inside the environment variable.


Array[String] get_env_files() const 🔗

Returns an Array of the file paths that have been currently loaded into the ENV singleton.


float get_env_float(key: String, default: float = 0.0) 🔗

Retrieves a floating-point double number from the environment variable explicitly casting parsing mechanics.


Dictionary get_env_group(prefix: String) 🔗

Retrieves a dictionary containing all environment variables that start with the exact specified prefix string.


int get_env_int(key: String, default: int = 0) 🔗

Retrieves a strict integer value from the environment variable mapping.


Vector2 get_env_vector2(key: String, default: Vector2 = Vector2(0, 0)) 🔗

Retrieves a Vector2 built from a comma-separated list of numerics stored in the environment variable.


Vector3 get_env_vector3(key: String, default: Vector3 = Vector3(0, 0, 0)) 🔗

Retrieves a Vector3 built from a comma-separated list of numerics stored in the environment variable.


Vector4 get_env_vector4(key: String, default: Vector4 = Vector4(0, 0, 0, 0)) 🔗

Retrieves a Vector4 built from a comma-separated list of numerics stored in the environment variable.


Dictionary get_envs_from_file(file: String) 🔗

Parses and returns a Dictionary of environment variables straight from the given file, without applying them to the global cache.


Dictionary get_envs_matching(pattern: String) 🔗

Retrieves a dictionary of environment variables that match the specified regular expression pattern string.


Array[String] get_missing_envs(keys: Array[String]) 🔗

Checks a list of keys and returns a String Array containing all keys that are currently missing from the loaded environment.


bool get_prioritize_os_env() const 🔗

Returns true if OS system environment variables continuously take precedence over user-loaded .env cached values.


bool has_env(key: String) 🔗

Returns true if the environment variable specified by the key exists within the mapped memory limit or system.


bool has_env_file(file: String) const 🔗

Returns true if the specified environment file path has already been processed and loaded.


Dictionary load_env_file(file: String, override: bool = true) 🔗

Loads environment configurations from the specified file path into the memory cache. Optionally overrides existing mapped variables.


Dictionary parse(data: String) 🔗

Parses the provided multi-line environment String data directly into a mapped key-value Dictionary.


Dictionary parse_buffer(data: PackedByteArray) 🔗

Parses the provided byte array buffer directly assuming standard UTF-8 environment rules, returning a mapped Dictionary.


Dictionary populate(env: Dictionary, override: bool = false) 🔗

Populates the underlying system module with variables loaded from the provided dictionary. Extends the existing configuration safely.


void push_to_os_env() 🔗

Pushes all currently loaded memory environment variables directly securely into the OS's environment context.


Dictionary refresh(override: bool = false) 🔗

Refreshes the loaded environment variables by attempting to reload previously accessed standard configurations.


void remove_env(key: String) 🔗

Removes an individual environment variable perfectly mapped under the specified key from the active limits.


bool require_envs(keys: Array[String]) 🔗

Checks an Array of keys, ensuring all are explicitly present. Returns false if any single key is missing from the environment cache.


void save(file: String) 🔗

Saves the fully evaluated current environment variables from memory tracking out to the target OS file.


void set_bool_whitelist(true_terms: Array[String], false_terms: Array[String]) 🔗

Sets explicit String arrays denoting what distinct term strings evaluate to true and false during get_env_bool queries.


void set_env(key: String, value: Variant) 🔗

Manually sets a specific environment variable directly to a Variant object within the cache, without updating an underlying file.


void set_prioritize_os_env(prioritize: bool) 🔗

Toggles if native external OS environment variables should be prioritized explicitly over local cached file maps during get requests.


void set_resolver(callable: Callable) 🔗

Overrides standard internal lookup mechanisms tightly applying a custom Callable for fetching runtime environment logic.