Skip to content

SettingsManager

Bases: SettingsBuilder, SettingsRoot

__init__

__init__(
    content_root_path: str | None = None,
    add_default_providers: bool = True,
) -> None

Initialize the settings manager.

Args: content_root_path: An optional path to be used as the root for resolving relative paths in settings sources. If not provided, the current working directory will be used as the content root path. add_default_providers: Whether to add the default settings providers.

add_aws_secrets_manager

add_aws_secrets_manager(
    secret_id: str,
    region: str | None = None,
    url: str | None = None,
) -> Self

Add a settings provider that reads settings values from AWS Secrets Manager.

add_azure_key_vault

add_azure_key_vault(
    url: str, credential: AsyncTokenCredential | None = None
) -> Self

Add a settings provider that reads settings values from Azure Key Vault.

add_defaults

add_defaults() -> Self

Add default settings providers in the recommended order.

add_environment_variables

add_environment_variables() -> Self

Add a settings provider that reads settings values from environment variables.

add_json_file

add_json_file(path: str, optional: bool = False) -> Self

Add a settings provider that reads settings values from a JSON file.

get_model

get_model(model_type: type[TModel]) -> TModel

Get a settings model of the specified type. The settings values will be mapped to the model fields by their names.

get_required_value

get_required_value(
    key: str, value_type: type[TField] | type[str] = str
) -> TField

Get a setting value by its key or raise an error if the key is not found or the value is None. Optionally, validate the setting value against the specified type.

get_section

get_section(key: str) -> SettingsSection

Get a settings section for the specified key. A settings section represents a subsection of the settings values that share a common key prefix.