API Reference
BaseConfig
dataclass
¶
Bases: ConfigHolder
Base class for the root of your configuration. Use it as a dataclass.
Supported types for configuration values: str, int, float, bool, and BaseSectionConfig
.
BaseSectionConfig
allows you to define another dataclass and use it as a section within the configuration.
To load the configuration, call the init
class method. You could use __init__
, but then you'd
have to manage some logic by yourself. Try to avoid that.
Source code in yaucl/base_config.py
26 27 28 29 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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
|
app_name
property
¶
Property to retrieve the application name.
This property attempts to determine the application name automatically if it is not explicitly set. If the name cannot be derived from the configuration class name, a ValueError is raised. In cases where the name is guessed, a warning is logged to indicate potential unpredictability in the deduced name.
Raises:
Type | Description |
---|---|
ValueError
|
If the application name is missing and cannot be guessed. |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The name of the application. |
conf_file_path
property
¶
Gets the configuration file path based on the provided configuration location
and file name. This property determines the path dynamically by considering
whether the provided configuration location is a Path
object or a string,
or defaults to a user-specific configuration directory if not explicitly set.
Returns:
Name | Type | Description |
---|---|---|
Path |
Path
|
The resolved configuration file path. |
generate_markdown_skeleton()
¶
Helper function that generates a Markdown skeleton for your documentation.
Consider adding descriptions to your options, examples, and more.
Source code in yaucl/base_config.py
init(app_name=None, load_from=None, conf_location=None, conf_file_name='config.toml')
classmethod
¶
Initialization of the Config Class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
app_name
|
str | None
|
The name of the application. Used in default paths and env variables. |
None
|
load_from
|
LOAD_FROM_TYPE | None
|
A list of file types to load configuration from. Defaults to ["toml", "env"] if not provided. Order matters, rightmost takes precedence. |
None
|
conf_location
|
Path | str | None
|
The location of the configuration file. If not provided, location will be determined based on the OS.
|
None
|
conf_file_name
|
str
|
The name of the configuration file. |
'config.toml'
|
Returns:
Name | Type | Description |
---|---|---|
Self |
Self
|
Configuration ready to go. |
Source code in yaucl/base_config.py
load(reset=False)
¶
Loads the data from specified sources and optionally resets before loading. This method loops through internal data sources and attempts to invoke corresponding update methods dynamically. If no update method is found for a source, a warning is logged.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
reset
|
bool
|
Whether to reset the current data before loading from the sources. Defaults to False. |
False
|
Source code in yaucl/base_config.py
update_from_env()
¶
Updates the config from environment variables.
Source code in yaucl/base_config.py
update_from_toml()
¶
Updates the config from a TOML file.
BaseSectionConfig
¶
Bases: ConfigHolder
Source code in yaucl/section_config.py
generate_markdown_skeleton(name)
¶
Generates a table with variables belonging to this section. Args: name: name under which this section is registered
Returns: string containing a Markdown table
Source code in yaucl/section_config.py
update_from_env(section_key, prefix)
¶
Looks for env variables that correspond to the section passed
Parameters:
Name | Type | Description | Default |
---|---|---|---|
section_key
|
str
|
key(name) of this section in the parent config |
required |
prefix
|
list[str]
|
prefixes from parents to construct env variable name |
required |
Returns: