Config
Config loads and exposes your project's config/*.cfg files for the currently selected environment. See the Configuration guide for a walkthrough of settings.cfg, database.cfg, and environment.cfg.
from grace.application import Application
app = Application()
app.load()
app.config.get("client", "guild_id")
app.config.database_uri
grace.config.Config
Config()
This class is the application configurations. It loads all the configuration for the given environment
The config environment is chosen by checking the value of the GRACE_ENV
environment variable. If the variable is not set it will load
with development by default (see Application.load).
There can be only one config loaded at once. Which means thar if you instantiate a second or multiple Config object, they will all share the same environment. This is to say, that the config objects are identical.
Source code in grace/config.py
75 76 77 78 79 80 81 82 83 84 85 | |
database
property
database
client
property
client
environment
property
environment
current_environment
property
current_environment
database_uri
property
database_uri
database_name
property
database_name
read
read(file)
Read the configuration file.
Source code in grace/config.py
128 129 130 | |
get
get(section_key, value_key, fallback=None)
Get the value from the configuration file.
| PARAMETER | DESCRIPTION |
|---|---|
section_key
|
The section key to get the value from.
TYPE:
|
value_key
|
The value key to get the value from.
TYPE:
|
fallback
|
The value to return if not found (default: None).
TYPE:
|
Source code in grace/config.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |
set_environment
set_environment(environment)
Set the environment for the configuration.
| PARAMETER | DESCRIPTION |
|---|---|
environment
|
The environment to set.
TYPE:
|
Source code in grace/config.py
150 151 152 153 154 155 156 | |
grace.config.EnvironmentInterpolation
Bases: BasicInterpolation
Interpolation which expands environment variables in values.
With this literal '${NAME}', the config will process the value from the given environment variable and use it as it's value in the config.
This includes exported environment variable (ex. 'export MY_VAR=...') and variable in '.env' files.
Usage example. token = ${MY_SECRET_VAR}
In the example above, token will take the value of the environment variable called 'MY_SECRET_VAR'. In case 'MY_SECRET_VAR' doesn't exist, the value will not be evaluated.
before_get
before_get(parser, section, option, value, defaults)
Interpolate the value before getting it from the parser.
| PARAMETER | DESCRIPTION |
|---|---|
parser
|
The parser to get the value from.
TYPE:
|
section
|
The section to get the value from.
TYPE:
|
option
|
The option to get the value from.
TYPE:
|
value
|
The value to interpolate.
TYPE:
|
defaults
|
The default values to use.
TYPE:
|
Source code in grace/config.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |