Case Studies
Config Overlay
Configuration overlays start with defaults and then apply environment-specific values.
Config Overlay
config_overlay.py
base = {
"debug": "false",
"region": "us",
"workers": "2",
}
dev = {
"debug": "true",
"workers": "1",
}
prod = {
"region": "eu",
"workers": "4",
}
environment =
config = base.copy()
if environment == "dev":
config.update(dev)
else:
config.update(prod)
parts = []
for key in sorted(config):
parts.append(key + "=" + config[key])
print("config=" + ";".join(parts))
base = {
"debug": "false",
"region": "us",
"workers": "2",
}
dev = {
"debug": "true",
"workers": "1",
}
prod = {
"region": "eu",
"workers": "4",
}
environment =
config = base.copy()
if environment == "dev":
config.update(dev)
else:
config.update(prod)
parts = []
for key in sorted(config):
parts.append(key + "=" + config[key])
print("config=" + ";".join(parts))
dictionary overlay
Copying defaults before update keeps the base configuration unchanged.