Flexible, simple, extensible settings loader from environment, AWS SSM, configparser .ini, and more.
Project description
layered-settings
layered-settings
is a simple and configurable hierarchical settings library for Python, including Django, Flask, or any other
scripts that need settings from potentially a variety of sources. With it you can load
settings from the environment, Amazon's SSM, local configparser .ini files, and more.
Installation
The package is available on pip as [layered-settings][layered-settings]. Run:
pip install layered-settings
then import via:
from layered_settings import initialize_settings,
A Usage Scenario
Example Usage
from layered_settings import initialize_settings
from layered_settings import loaders
get_setting = initialize_settings(
sources=[
# Lowest priority is setting-defaults.ini. All configuration values should be defaulted in here.
loaders.ConfigParserLoader(os.path.join(SCRIPT_DIR, "inifiles", "setting-defaults.ini")),
# The `loaders.ConfigParserLoader` is optional - if you pass a string ending in .ini, it wraps it in
# a `loaders.ConfigParserLoader` for you.
os.path.join(SCRIPT_DIR, "inifiles", "setting-overrides.ini"),
# If ENV is set and we are able/willing to reach out to AWS, do so..
loaders.SSMLoader(f"/app/stage/", aws_region="us-east-1") if ALLOW_SSM_CONFIGURATION else None,
# Top priority -- env var in the format APP__section__key.
loaders.EnvLoader("APP__{section}__{key}"),
]
)
DATABASE_HOST = get_setting("database", "DATABASE_HOST")
AWS_SECRET_KEY = get_setting("aws", "AWS_SECRET_KEY")
...
Frameworks Supported
This library is tested using Python 3.x.
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
layered-settings-1.0.0.tar.gz
(5.3 kB
view hashes)
Built Distributions
layered_settings-1.0.0-py3.8.egg
(14.5 kB
view hashes)
Close
Hashes for layered_settings-1.0.0-py3.8.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | a88995de2d28c501b3a26dc93c5a326767f906388d1f98e700bc356373d56f77 |
|
MD5 | 3f64c8f56bc7fd9b59d99b7f800805e0 |
|
BLAKE2b-256 | df740672bb9a73933ed143f2e06a3fb0415078e16be79b04d6f1534d5ea9b883 |
Close
Hashes for layered_settings-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57e5b9ed777492bcec4aad48d906c74f0bdacf23a3897084815ab18c7b9c3299 |
|
MD5 | 70c4991d7770e2b04ee14e36a1989b0f |
|
BLAKE2b-256 | 00802775a11b1b13f0b24dd832e074cd669d8144b4f86ee28379f777ff91e8e5 |