Getters¶
Functions used to retrieve proxies around values in a
staticconf.config.ConfigNamespace
. All of the getter methods
return a ValueProxy
. These proxies are wrappers around a configuration
value. They don’t access the configuration until some attribute of the object
is accessed.
Warning
This module should be considered deprecated. There are edge cases which
make these getters non-obvious to use (such as passing a ValueProxy
to a cmodule.
Please use staticconf.readers
if you don’t need static
definitions, or staticconf.schema
if you do.
Example¶
import staticconf
# Returns a ValueProxy which can be used just like an int
max_cycles = staticconf.get_int('max_cycles')
print "Half of max_cycles", max_cycles / 2
# Using a NamespaceGetters object to retrieve from a namespace
config = staticconf.NamespaceGetters('special')
ratio = config.get_float('ratio')
To retrieve values from a namespace, you can create a NamespaceGetters
object.
my_package_conf = staticconf.NamespaceGetters('my_package_namespace')
max_size = my_package_conf.get_int('max_size')
error_msg = my_package_conf.get_string('error_msg')
Arguments¶
Getters accept the following kwargs:
- config_key
- string configuration key
- default
- if no
default
is given, the key must be present in the configuration. Raises ConfigurationError on missing key. - help
- a help string describing the purpose of the config value. See
staticconf.config.view_help()
. - namespace
- get the value from this namespace instead of DEFAULT.
Proxy¶
Proxy a configuration value. Defers the lookup until the value is used, so that values can be read statically at import time.
-
class
staticconf.proxy.
ValueProxy
(validator, namespace, key, default=<Undefined>)[source]¶ Proxy a configuration value so it can be loaded after import time.