Basic Usage

Installation

Install using pip:

(.venv) $ pip install confident

Load Environment Variables

Simply create an object. Confident will load the property value from environment variable with the same name if exists.

 1import os
 2
 3from confident import Confident
 4
 5
 6os.environ['port'] = 3000
 7
 8class MyConfig(Confident):
 9    port: int
10
11config = MyConfig()
12
13print(config)
14#> port=3000

Load Default Values

Like in dataclass and pydantic classes, it is possible to declare default values of properties.

 1from confident import Confident
 2
 3
 4class MyConfig(Confident):
 5    port: int = 3333
 6
 7config = MyConfig()
 8
 9print(config)
10#> port=3333

Load Config Files

Confident supports json, yaml and .env files.

app_config/config1.json

{
  "title": "my_app_1",
  "retry": true,
  "timeout": 10
}

app_config/config2.yaml

title: my_yaml_app
port: 3030
 1from confident import Confident
 2
 3
 4class MyConfig(Confident):
 5    title: str
 6    port: int = 5000
 7    retry: bool = False
 8
 9config = MyConfig(files=['app_config/config1.json', 'app_config/config2.yaml'])
10
11print(config)
12#> title='my_app_1' port=3030 retry=True