Batteries

Powerful batteries for bootstrapping Concrete Settings in your projects.

Sources

The built-in sources are automatically registered when concrete_settings is imported. This means that calling for example setting.update('/path/to/settings.yaml') would automatically invoke YamlSource.

Most of the provided sources read the files into memory and store them as Python dicts. Updating a setting from such source ends up in querying a dict like: internal_dict[setting_name].

class concrete_settings.contrib.sources.EnvVarSource[source]

Updates settings from environmental variables.

A nested setting’s parent attribute name is expected to be in upper case and separated by “_”. For example, consider that an environmental variable DB_HOST is set as follows:

export DB_HOST=my-db-server.com

And here is a nested settings structure updated from environmental variables source:

from concrete_settings import Settings
from concrete_settings.contrib.sources import EnvVarSource

class DatabaseSettings(Settings):
    HOST: str = 'localhost'

class AppSettings(Settings):
    DB = DatabaseSettings()

app_settings = AppSettings()
app_settings.update(EnvVarSource())
print(app_settings.DB.HOST)

Output:

my-db-server.com
class concrete_settings.contrib.sources.PythonSource(path)[source]

Allows updating settings from Python files (*.py) with settings corresponding to top-level variables, such as:

ADMIN_EMAIL = 'alex@example.com'

DEBUG = True

# can be read as nested settings
DB = {
    HOST: '127.0.0.1'
    PORT: 5432
}
class concrete_settings.contrib.sources.YamlSource(path)[source]

Allows updating settings from YAML files (*.yml; *.yaml):

DEBUG: true

ADMIN_EMAIL: alex@example.com

DB:
    HOST: 127.0.0.1
    PORT: 5432
class concrete_settings.contrib.sources.JsonSource(path)[source]

Allows updating settings from JSON files (*.js; *.json)

{
   "DEBUG": true,

   "ADMIN_EMAIL": "alex@example.com",

   "DB": {
       "HOST": "127.0.0.1"
       "PORT": 5432
   }
}

Frameworks

Django

class concrete_settings.contrib.frameworks.django30.Django30Settings(**kwargs)[source]

Parent class for Django 3.0 -based settings. The default values correspond to the default values of django.conf.global_settings.