Documentation

Examples

A common minimal use of staticconf would be to use a single yaml configuration
file and read some values from it.

importstaticconffilename='hosts.yaml'namespace='hosts'# Load configuration from the file into namespace `hosts`staticconf.YamlConfiguration(filename,namespace=namespace)...# Some time later on, read values from that namespaceprintstaticconf.read('database.slave',namespace=namespace)printstaticconf.read('database.master',namespace=namespace)

hosts.yaml might look something like this:

database:slave:dbslave_1master:dbmaster_1

A more involved example would load configuration from multiple files, create
a watcher for reloading, and read some config values.

fromfunctoolsimportpartialimportosimportstaticconfdefload_config(config_path,defaults='~/.myapp.yaml`)# First load global defaults if the file existsstaticconf.INIConfiguration('/etc/myapp.ini',optional=True)# Next load user defaultsstaticconf.YamlConfiguration(defaults,optional=True)# Next load the specified configuration filestaticconf.YamlConfiguration(config_path)# Now let's override it with some environment settingsstaticconf.DictConfiguration((k[5:].lower(),v)fork,vinos.environifk.startswith('MYAPP_'))defbuild_watcher(filename):returnstaticconf.ConfigFacade.load(filenames,'DEFAULT',partial(load_config,filename))defrun(config_path):watcher=build_watcher(config_path)whileis_work():watcher.reload_if_changed()current_threshold=staticconf.read_float('current_threshold')do_some_work(current_thresold)