API¶
All public functions of the Gila
class are available in the singleton instance
with the addition of gila.reset()
, which will reset the singleton
instance back to empty.
-
class
Gila
¶ An instance of the Gila config store
-
add_config_path
(filepath: str)¶ Adds a filepath to the list of filepaths to search for config files The filepath can be either an absolute path or a path relative to the current working directory
- Parameters
filepath –
str
: The filepath to be added
-
all_config
()¶ Returns a dictionary representing all of the current config values with the overrides in place.
-
automatic_env
()¶ Tells Gila to automatically load env vars that start with the env_prefix, if set.
-
bind_env
(key: str, env_key: str = None)¶ Binds a given key to an environemnt variable. Default usage with bind_env(key) would bind the config value
key
with the environment valueKEY
. If an env_key is passed in, it will be used instead of the default uppercased key. eg bind_env(key, env_key) will bind the config value ofkey
toENV_KEY
.NOTE: If env_key is not passed in, the key will be merged with a given prefix, should one exist.
-
debug
()¶ Prints all of the instance internal dictionaries for debugging purposes
-
deregister_alias
(alias: str)¶ Removes an alias for a key in the config store.
- Parameters
alias –
str
: Alias to remove from config store
-
get
(key: str)¶ This fetches a value from the config store for a given key. Returns None if no value is found.
The order of precedence on get is: overrides > environment variables > config vars > default values.
- Parameters
key –
str
: The key to search the config store for
-
in_config
(key: str)¶ Checks if a given key is found in the config file provided. Returns false if no file has been loaded in yet
- Parameters
key –
str
: key to check in config values
-
override
(key: str, value: Any)¶ Sets the override value for a given key. Override values will take precedence over all other found values of a given key
- Parameters
key –
str
: The key in the config storevalue – Any: The override value to be set for the key
-
override_with_env
(prefix: str)¶ Finds all env vars with given prefix and sets them as overrides with a lowercase key. This would allow for a one-time load of environment vars to the config store. The loaded env vars will be loaded in as overrides, meaning they will take precedence over all other values
- Parameters
prefix –
str
: The prefix for Gila to use while searching.
-
read_config_file
()¶ Will read in config from file. Gila will iterate through the given filepaths, and return the first file found in a config path that has the extension that is set with gila.set_config_type() if it is set, or the first file with a supported filetype.
-
register_alias
(alias: str, key: str)¶ Registers an alias for a given key. When a key has an alias, gila.Get(key) and gila.Get(alias) will return the same value
-
remove_default
(key: str)¶ Remove the default key.
- Parameters
key –
str
: The real key in the config store
-
remove_override
(key: str)¶ Removes the override for a key, if it is currently set
- Parameters
key –
str
: They key to remove the override for
-
reset
()¶ Resets all of the values in the singleton instance of Gila
-
set_config_file
(filepath: str)¶ Sets the filepath to the intended config file. This is an increased level of verbosity than set_config_name and set_config_type, as if the config file is set, Gila will only look for the config file in that one location.
- Parameters
filepath –
str
: The filepath to the intended config file
-
set_config_name
(filename: str)¶ Sets the filename that Gila will look for. If the filename is set and the config type is not, Gila will search for a config file with the given config name and any of the supported extensions
- Parameters
filename –
str
: The name of the config file that Gila should look for
-
set_config_type
(filetype: str)¶ Sets the file extension that gila should look for - if not set, gila will look for a file with any of the supported filetypes.
- Parameters
filetype –
str
: The extension of the config file that Gila should look for
-
set_default
(key: str, value: Any)¶ Sets the default value for key to value. If no other values are found when running gila.get(key), the default value will be returned.
- Parameters
key –
str
: The real key in the config storevalue – Any: The default value to be set for the key
-
set_env_prefix
(prefix: str)¶ Sets the prefix that the automatic environment loader will use to find values for a given key. For instance, set_env_prefix(“prefix”) will set the prefix Gila is looking for to
PREFIX_
. This means that when gila.get(“key”) is ran and automatic_env is enabled, Gila will look for the value inPREFIX_KEY
- Parameters
prefix –
str
: The prefix to be added. This value will be uppercased and have “_” suffixed
-
unbind_env
(key: str)¶ Removes a binding between an env_var and a key, if it exists
- Parameters
key –
key
-