configstruct package


configstruct.config_struct module

class configstruct.config_struct.ConfigStruct(config_file, log_options_parent=None, **sections_defaults)[source]

Bases: configstruct.open_struct.OpenStruct

Provides simplified access for managing typed configuration options saved in a file.

  • config_file – path to file that should house configuration items.
  • log_options_parent – option key to use if this instance is expected to use the LOG_OPTIONS default values and allow configuration of basic logging
  • sections_defaults – options that are provided as defaults (will be overridden by any options read from the config_file)
configure_basic_logging(main_module_name, **kwargs)[source]

Use common logging options to configure all logging.

Basic logging configuration is used to set levels for all logs from the main module and to filter out logs from other modules unless they are of one level in priority higher.

Parameters:main_module_name – name of the primary module for normal logging
save(conflict_resolver=<function choose_mine>)[source]

Save all options in memory to the config_file.

Options are read once more from the file (to allow other writers to save configuration), keys in conflict are resolved, and the final results are written back to the file.

Parameters:conflict_resolver – a simple lambda or function to choose when an option key is provided from an outside source (THEIRS, usually a file on disk) but is also already set on this ConfigStruct (MINE)
class configstruct.config_struct.OtherLoggingFilter(whitelisted_module, minimum_other_level)[source]

Bases: logging.Filter

Quell logs from other modules using a different minimum level.

configstruct.config_struct.choose_mine(section, option, mine, theirs)[source]

Always prefer values for keys in memory.

configstruct.config_struct.choose_theirs(section, option, mine, theirs)[source]

Always prefer values for keys from file.

configstruct.open_struct module

class configstruct.open_struct.OpenStruct[source]

Bases: dict

Base wrapper to allow direct method access to item keys.

configstruct.section_struct module

class configstruct.section_struct.SectionStruct(name, **items)[source]

Bases: configstruct.open_struct.OpenStruct

Provides method access to a set of items.


Items to take precedence if their values are not None (never saved)

sync_with(config, conflict_resolver)[source]

Synchronizes current set of key/values in this instance with those in the config.

Module contents