Python 3.9 is now generally available.


A registry containing library configuration values.

Inherits From: expected_type

modname The module name that needs to be imported.



View source

Tries to import the configuration module if it is not already imported.

This function always sets self._module to a value that is not None; either the imported module (if it was imported successfully) or a placeholder object() instance (if an ImportError was raised) is used. Other exceptions are not caught.

When a placeholder instance is used, the instance is also put in sys.modules. This usage allows us to detect when sys.modules was changed (as does when it notices source code changes) and retries the import_module in that case, while skipping it (for speed) if nothing has changed.

import_func Used for dependency injection.


View source

Registers a set of configuration names.

prefix A shared prefix for the configuration names being registered. If the prefix doesn't end in _, that character is appended.
mapping A dict that maps suffix strings to default values.

A ConfigHandle instance.

You can re-register the same prefix. When you do so, the mappings are merged, and for duplicate suffixes, the most recent registration is used.


View source

Drops the imported configuration module.

If the configuration module has not been imported, no operation occurs, and the next operation takes place.