Skip to content

Basic Usage

Load Environment Variables

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

import os

from confident import BaseConfig


os.environ['port'] = 3000

class MyConfig(BaseConfig):
    port: int

config = MyConfig()

print(config)

#> port=3000

Load Default Values

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

from confident import BaseConfig


class MyConfig(BaseConfig):
    port: int = 3333

config = MyConfig()

print(config)

#> 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
from confident import BaseConfig


class MyConfig(BaseConfig):
    title: str
    port: int = 5000
    retry: bool = False

config = MyConfig(_files=['app_config/config1.json', 'app_config/config2.yaml'])

print(config)

#> title='my_app_1' port=3030 retry=True