Configure-Tron
Configuretron enables type hinted configuration files and secrets for python. Easily add secrets to your configuration that are encryptable from clients and decryptable from trusted developers and running services.
Features
- Type-hinted configuration
- Simple, readable YAML configs
- Config in source control
- Secrets safely in source control
- Easily swap environments
- Control who can encrypt and decrypt
Installation
$ python -m pip install configuretron
Usage
config.yml
config:
api_url: https://apitopia.com/api/v1
api_timeout: 20
config.py
@dataclass
class Config:
api_url: str
api_timeout: int = 30
config = configuretron.from_yaml(Config, "config.yml")
Adding Secrets
Adding encryption just takes a few console commands
$ python -m configuretron --yaml=config.yml setup_encryption
Copy the generated base64 private key into an environment variable (in this example, PRIVATE_KEY)
Encrypt and variables in the config (in this example, api_token):
$ python -m configuretron --yaml=config.yml encrypt --key api_token
Then pass the key to the config
private_key = configuretron.env_base64_value('PRIVATE_KEY')
config = configuretron.from_yaml(Config, "config.yml", private_key=private_key)
Environmental overrides
To override values per-environment, add them into the config like so:
config:
api_url: http://localhost:8080/api/v1
api_timeout: 20
env:
prod:
config:
api_url: https://apitopia.com/api/v1
Then just pass env when initializing the configuration:
config = configuretron.from_yaml(Config, "config.yml", env="prod")
TODO Features
- Config heirarchy
- Type validation
- Multiple layered configs