douglasfarinelli / confdaora

Configurations using python annotations

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

confdaora

confdaora

Configurations using python annotations


Documentation:

Source Code:


Key Features

  • Generate a DictDaora with values parsed from environment variables.

Requirements

  • Python 3.6+
  • dictdaora
  • jsondaora

Instalation

$ pip install confdaora

Basic example

from typing import TypedDict

from confdaora import confdaora_env


class AppConfig(TypedDict):
    port: int
    host: str


config = confdaora_env(AppConfig)

print(config)

Suposing your file calls myconf.py:

PORT=8080 HOST=localhost python myconf.py

{'port': 8080, 'host': 'localhost'}

Complex example

from typing import List, TypedDict

from confdaora import confdaora_env


DBConfig = TypedDict('DBConfig', {'port': int, 'host': str})
DBConfig.__prefix__ = 'db'
DBConfig.port = 3306

KeyConfig = TypedDict('KeyConfig', {'name': str, 'values': List[int]})
KeyConfig.__prefix__ = 'keys'


class AppConfig(TypedDict):
    port: int = 8080
    host: str
    db: DBConfig
    keys: List[KeyConfig]


config = confdaora_env(AppConfig)

print(config)

Suposing your file calls myconf.py:

HOST=localhost \
DB_HOST=localhost \
KEYS_0_NAME=test \
KEYS_0_VALUES=10,20 \
KEYS_1_NAME=test2 \
KEYS_1_VALUES=30,40 \
python myconf.py

{'port': 8080, 'host': 'localhost', 'db': {'port': 3306, 'host': 'localhost'}, 'keys': [{'name': 'test', 'values': [10, 20]}, {'name': 'test2', 'values': [30, 40]}]}

About

Configurations using python annotations

License:MIT License


Languages

Language:Python 97.5%Language:Makefile 2.5%