API

This part of the documentation briefly covers the interfaces of Concrete Settings.

Settings

class concrete_settings.settings.setting
class concrete_settings.settings.PropertySetting

@setting (an alias to PropertySetting decorator-class) is used to mark class methods as settings. The property-settings are read-only and used to compute a value, usually based on other settings. For example:

class AppSettings(Settings):
    ADMIN_NAME: str = 'Alex'
    ADMIN_EMAIL: str = 'alex@example.com'

    @setting
    def ADMIN_FULL_EMAIL(self) -> str:
        """Full admin email in `name <email>` format"""
        return f'{self.ADMIN_NAME} <{self.ADMIN_EMAIL}>'

Note that methods written in UPPER_CASE are converted to PropertySetting automatically and do not require decoration by @setting.

Types

Validators

ValueTypeValidator

RequiredValidator

DeprecatedValidator

Behaviors

override

Sets Setting.override = True.

Usage:

from concrete_settings import Settings, override

class BaseSettings(Settings):
    SECRET: int = 100200300400500
    ...

class DevSettings(BaseSettings):
    SECRET: str = 'abcdef12345' @override

validate

Provides behavior-style way of attaching validators to a setting.

from concrete_settings import Settings, validate, ValidationError

def is_positive(value, **kwargs):
    if value <= 0:
        raise ValidationError(f'must be a positive integer')

class AppSettings(Settings):
    SPEED: int = 20 @ validate(is_positive)

app_settings = AppSettings()
app_settings.SPEED = -10

print(app_settings.is_valid())
print(app_settings.errors)
False
{'SPEED': ['must be a positive integer']}

required

deprecated

Sources

concrete_settings.sources.AnySource

AnySource = Union[Dict[str, Any], str, 'Source', Path]

Valid settings sources types union. A valid source is either a dict, an instance of Source or a path (str or Path)

Update strategies