settings Module

Provide access to settings for globally used Azure configuration values.

Classes

Settings

Settings for globally used Azure configuration values.

You probably don't want to create an instance of this class, but call the singleton instance:


   from azure.common.settings import settings
   settings.log_level = log_level = logging.DEBUG

The following methods are searched in order for a setting:

  1. immediate values
  2. previously user-set value
  3. environment variable
  4. system setting
  5. implicit default

An implicit default is (optionally) defined by the setting attribute itself.

A system setting value can be obtained from registries or other OS configuration for settings that support that method.

An environment variable value is obtained from os.environ

User-set values many be specified by assigning to the attribute:


   settings.log_level = log_level = logging.DEBUG

Immediate values are (optionally) provided when the setting is retrieved:


   settings.log_level(logging.DEBUG())

Immediate values are most often useful to provide from optional arguments to client functions. If the argument value is not None, it will be returned as-is. Otherwise, the setting searches other methods according to the precedence rules.

Immutable configuration snapshots can be created with the following methods:

  • settings.defaults returns the base defaultsvalues , ignoring any environment or system or user settings

  • settings.current returns the current computation of settings including prioritizatiom of configuration sources, unless defaults_only is set to True (in which case the result is identical to settings.defaults)

  • settings.config can be called with specific values to override what settings.current would provide


   # return current settings with log level overridden
   settings.config(log_level=logging.DEBUG)

>>> import logging
>>> from azure.core.settings import settings
>>> settings.log_level = logging.DEBUG
>>> settings.log_level()
10

>>> settings.log_level(logging.WARN)
30