waterbutler package¶
waterbutler.constants module¶
Constants
waterbutler.settings module¶
-
class
waterbutler.settings.
SettingsDict
(*args, parent=None, **kwargs)[source]¶ Bases:
dict
Allow overriding on-disk config via environment variables. Normal config is done with a hierarchical dict:
"SERVER_CONFIG": { "HOST": "http://localhost:7777" }
HOST
can be retrieved in the python code with:config = SettingsDict(json.load('local-config.json')) server_cfg = config.child('SERVER_CONFIG') host = server_cfg.get('HOST')
To override a value, join all of the parent keys and the child keys with an underscore:
$ SERVER_CONFIG_HOST='http://foo.bar.com' invoke server
Nested dicts can be handled with the
.child()
method. Config keys will be all parent keys joined by underscores:"SERVER_CONFIG": { "ANALYTICS": { "PROJECT_ID": "foo" } }
The corresponding envvar for
PROJECT_ID
would beSERVER_CONFIG_ANALYTICS_PROJECT_ID
.-
get
(key, default=None)[source]¶ Fetch a config value for
key
from the settings. First checks the env, then the on-disk config. If neither exists, returnsdefault
.
-
get_bool
(key, default=None)[source]¶ Fetch a config value and interpret as a bool. Since envvars are always strings, interpret ‘0’ and the empty string as False and ‘1’ as True. Anything else is probably an acceident, so die screaming.
-
get_nullable
(key, default=None)[source]¶ Fetch a config value and interpret the empty string as None. Useful for external code that expects an explicit None.
-
waterbutler.sizes module¶
A utility module for writing legible static numbers >>> 10 * MBs >>> 6 * GBs