settings
oxytcmri.infrastructure.settings
¶
This module provides classes for managing application settings.
The Settings
class encapsulates the Dynaconf settings object and provides a clear interface for accessing and
modifying settings. It allows for easy access and modification of settings using attribute-style access.
The ModuleSettings
class is a helper class within Settings
. It handles the settings of individual modules, providing
attribute-style access to the module's settings.
Example¶
Suppose you have a settings file tests-data/test_settings.toml
with the following content:
[database]
url = "sqlite:///test-data/test.db"
You can then use the Settings
class to access the settings as follows:
>>> settings = Settings("tests-data/test_settings.toml")
>>> print(settings.database.url)
sqlite:///test-data/test.db
Classes:
Name | Description |
---|---|
Settings |
A class to manage application settings. |
ModuleSettings |
A helper class to handle the settings of individual modules. |
Settings(filename)
¶
A class to manage application settings.
This class encapsulates the Dynaconf settings object and provides a clear interface for accessing and modifying settings.
Attributes:
Name | Type | Description |
---|---|---|
filepath |
Path
|
The path to the settings file. |
_dynaconf_settings |
Dynaconf
|
The Dynaconf settings object. |
Methods:
Name | Description |
---|---|
__getattr__ |
Retrieve the value of the attribute with the given name. |
__setattr__ |
Set the value of the attribute with the given name. |
Examples:
>>> settings = Settings("tests-data/test_settings.toml")
>>> print(settings.database.url)
sqlite:///test-data/test.db
Constructs all the necessary attributes for the Settings object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename
|
str
|
The path to the settings file. |
required |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the settings file does not exist. |
Source code in oxytcmri/infrastructure/settings.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
|
filepath = filepath
instance-attribute
¶
base_dir = filepath.parent
instance-attribute
¶
to_toml(filepath)
¶
Convert the settings to a string in TOML format and save it to a file.
Returns:
Type | Description |
---|---|
str
|
The settings as a TOML string. |
Source code in oxytcmri/infrastructure/settings.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
|
ModuleSettings(module_name, dynabox, filepath)
¶
A helper class to handle the settings of individual modules.
This class encapsulates the settings of a specific module and provides attribute-style access to the module's settings.
Attributes:
Name | Type | Description |
---|---|---|
module_name |
str
|
The name of the module. |
_dynabox |
DynaBox
|
The DynaBox object that holds the actual settings. |
filepath |
Path
|
The path to the settings file. |
Methods:
Name | Description |
---|---|
__getattr__ |
Retrieve the value of the attribute with the given name. |
__setattr__ |
Set the value of the attribute with the given name. |
Constructs all the necessary attributes for the ModuleSettings object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
module_name
|
str
|
The name of the module. |
required |
dynabox
|
DynaBox
|
The DynaBox object that holds the actual settings. |
required |
filepath
|
Path
|
The path to the settings file. |
required |
Source code in oxytcmri/infrastructure/settings.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
|
module_name = module_name
instance-attribute
¶
filepath = filepath
instance-attribute
¶
list_attributes()
¶
List all the attributes of the module.
Returns:
Type | Description |
---|---|
list
|
A list of all the module's attributes. |
Source code in oxytcmri/infrastructure/settings.py
244 245 246 247 248 249 250 251 252 253 |
|