Share via


Settings Class

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.core.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 prioritization 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

Constructor

Settings()

Variables

Name Description
log_level

a log level to use across all Azure client SDKs (AZURE_LOG_LEVEL)

tracing_enabled

Whether tracing should be enabled across Azure SDKs (AZURE_TRACING_ENABLED)

tracing_implementation

The tracing implementation to use (AZURE_SDK_TRACING_IMPLEMENTATION)

Methods

config

Return the currently computed settings, with values overridden by parameter values.

Examples:


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

config

Return the currently computed settings, with values overridden by parameter values.

Examples:


   # return current settings with log level overridden
   settings.config(log_level=logging.DEBUG)
config(**kwargs: Any) -> Tuple[Any, ...]

Returns

Type Description
<xref:namedtuple>

The current values for all settings, with values overridden by parameter values

Attributes

azure_cloud

Return a value for a global setting according to configuration precedence.

The following methods are searched in order for the setting:

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

If a value cannot be determined, a RuntimeError is raised.

The env_var argument specifies the name of an environment to check for setting values, e.g. "AZURE_LOG_LEVEL". If a convert function is provided, the result will be converted before being used.

The optional system_hook can be used to specify a function that will attempt to look up a value for the setting from system-wide configurations. If a convert function is provided, the hook result will be converted before being used.

The optional default argument specified an implicit default value for the setting that is returned if no other methods provide a value. If a convert function is provided, default will be converted before being used.

A convert argument may be provided to convert values before they are returned. For instance to concert log levels in environment variables to logging module values. If a convert function is provided, it must support str as valid input type.

azure_cloud: PrioritizedSetting[str | AzureClouds, AzureClouds]

current

Return the current values for all settings.

Returns

Type Description
<xref:namedtuple>

The current values for all settings

defaults

Return implicit default values for all settings, ignoring environment and system.

Returns

Type Description
<xref:namedtuple>

The implicit default values for all settings

defaults_only

Whether to ignore environment and system settings and return only base default values.

Returns

Type Description

Whether to ignore environment and system settings and return only base default values.

log_level

Return a value for a global setting according to configuration precedence.

The following methods are searched in order for the setting:

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

If a value cannot be determined, a RuntimeError is raised.

The env_var argument specifies the name of an environment to check for setting values, e.g. "AZURE_LOG_LEVEL". If a convert function is provided, the result will be converted before being used.

The optional system_hook can be used to specify a function that will attempt to look up a value for the setting from system-wide configurations. If a convert function is provided, the hook result will be converted before being used.

The optional default argument specified an implicit default value for the setting that is returned if no other methods provide a value. If a convert function is provided, default will be converted before being used.

A convert argument may be provided to convert values before they are returned. For instance to concert log levels in environment variables to logging module values. If a convert function is provided, it must support str as valid input type.

log_level: PrioritizedSetting[str | int, int]

tracing_enabled

Return a value for a global setting according to configuration precedence.

The following methods are searched in order for the setting:

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

If a value cannot be determined, a RuntimeError is raised.

The env_var argument specifies the name of an environment to check for setting values, e.g. "AZURE_LOG_LEVEL". If a convert function is provided, the result will be converted before being used.

The optional system_hook can be used to specify a function that will attempt to look up a value for the setting from system-wide configurations. If a convert function is provided, the hook result will be converted before being used.

The optional default argument specified an implicit default value for the setting that is returned if no other methods provide a value. If a convert function is provided, default will be converted before being used.

A convert argument may be provided to convert values before they are returned. For instance to concert log levels in environment variables to logging module values. If a convert function is provided, it must support str as valid input type.

tracing_enabled: PrioritizedSetting[str | bool | None, bool]

tracing_implementation

Return a value for a global setting according to configuration precedence.

The following methods are searched in order for the setting:

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

If a value cannot be determined, a RuntimeError is raised.

The env_var argument specifies the name of an environment to check for setting values, e.g. "AZURE_LOG_LEVEL". If a convert function is provided, the result will be converted before being used.

The optional system_hook can be used to specify a function that will attempt to look up a value for the setting from system-wide configurations. If a convert function is provided, the hook result will be converted before being used.

The optional default argument specified an implicit default value for the setting that is returned if no other methods provide a value. If a convert function is provided, default will be converted before being used.

A convert argument may be provided to convert values before they are returned. For instance to concert log levels in environment variables to logging module values. If a convert function is provided, it must support str as valid input type.

tracing_implementation: PrioritizedSetting[str | Type[AbstractSpan] | None, Type[AbstractSpan] | None]