Use program language like python for config, when json/yaml/toml is not enough. This sacrificed runtime safety, so only run trusted code(Beware eval(), exec() used and import packages)
see defaultConfig.py
# defaultConfig.py
from typing import *
from dataclasses import dataclass
from runtime_type_checker import check_types
from turing_config import sync_config, bind_config
from pathlib import Path
@check_types
@dataclass
@sync_config(package=__package__) # or @config(path=Path(...)) manually
class Config:
mode: Literal["dev", "prod", "test"] = "dev"
port: int = 8000
CONFIG = bind_config(Config)