Builds a config object based on environment variables, settings files and (optional) parameters stored in AWS System Manager Parameter Store.
Project description
Manage Conf
Description
Builds a config object based on environment variables, settings files and (optional) parameters stored in AWS System Manager Parameter Store.
The config object merges in config, overriding any previous key/value pairs, in the following order:
- ENV
- default config: default.json
- stage config: {stage}.json
- remote config: remote_settings (AWS param store)
Available to download as a package on PyPi.
Settings Files
Set an environment variable with the key name project_config_dir
. It is important this is set before the package is imported. The value of project_config_dir
should be the location of your /settings
folder.
Set-up your settings folder, adding in configuration to the appropriate file.
.
├── settings <-- Settings folder
│ ├── default.json <-- default configuration
│ ├── {stage}.json <-- stage specific configuration e.g. `local`
│ └── {stage}.json <-- stage specific configuration e.g. `dev`
Example configuration:
default.json
{
"project_name": "example-project",
"DEBUG": "False"
}
local.json
{
"DEBUG": "True",
"local_or_remote_settings": "local"
}
Local config object:
{
"project_name": "example-project",
"DEBUG": "True,
"local_or_remote_settings": "local"
}
dev.json
{
"local_or_remote_settings": "remote"
}
Dev config object:
{
"project_name": "example-project",
"DEBUG": "True",
"local_or_remote_settings": "remote",
# and any remote settings from AWS param store
}
AWS
Add parameters in your AWS account with paths that match this pattern:
/{project_name}/{stage}/
If you set "local_or_remote_settings": "remote"
in a remote {stage}.json
config file, the package will attempt to fetch the parameters from the store that have this base path.
Using the example configuration above, the path would be:
/example-project/dev/
Usage
Make sure project_config_dir
is set before importing the library.
from manageconf import Config, get_config
SECRET_KEY = get_config("SECRET_KEY")
DEBUG = get_config("DEBUG", True)
# default values are an optional second arg and will
# be used if the param cannot be found in the config object
Development
Install
Requires Poetry.
# create a Python3 virtual environment
virtualenv -p python3 env
# activate the virtual env
source env/bin/activate
# install requirements
poetry install
Tests
# run tests
pytest -vv
# coverage report in the Terminal
pytest --cov=manageconf tests/
# coverage report in HTML
pytest --cov-report html --cov=manageconf tests/
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for manageconf-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b80490d5985e3882d0472f4f257a5422d89f5f5075aa61ad24634c213a9f458 |
|
MD5 | b1edf78a38236869b6640918f0b5f97f |
|
BLAKE2b-256 | dcb55e1139de4cd5f56cbf2b4c3facbf8339044cba7990c1d0caeaf569d56b0a |