Object Settings
ConfidentConfig class
In addition to defining the object’s behaviour by inserting key-value arguments, it is possible to change class behaviour using ConfidentConfig class. This configuration method is similar to pydantic Config model.
1from confident import Confident
2
3class MyConfig(Confident):
4 title: str
5 port: int = 5000
6 retry: bool = False
7
8 class ConfidentConfig: # In this class the specifications of `MyConfig` will be defined.
9 deployment_config = 'deploy.json'
10 files = ['app_config/config1.json', 'app_config/config2.yaml']
11 ignore_missing_files = True
This is equivalent to:
1from confident import Confident
2
3class MyConfig(Confident):
4 title: str
5 port: int = 5000
6 retry: bool = False
7
8config = MyConfig(
9 deployment_config='deploy.json',
10 files=['app_config/config1.json', 'app_config/config2.yaml'],
11 ignore_missing_files = True
12)
Changing The Loading Priority
It is possible to change the loading order of fields from different sources. If a field value is present in multiple sources, the value from the highest priority source will be chosen and override the others. source_priority is an attribute that holds a list of ConfigSource enums - The first will have the highest priority and the last will have the lowest. Sources that their enum will not appear in the `source_priority` list, will not be loaded to the created object.
1from confident import Confident, ConfigSource
2
3 class MyConfig(Confident):
4 host: str
5 port: int = 5000
6
7 class ConfidentConfig:
8 # Here we define that environment vars will have the highest priority (even before explicit values).
9 # Values from files and deployments will have lower priority than default values.
10 source_priority = [
11 ConfigSource.env_var, ConfigSource.explicit, ConfigSource.class_default, ConfigSource.deployment, ConfigSource.file
12 ]