Application configuration

FrescoApp has an options property that can be used for your application’s configuration. A common pattern is for your application to provide default settings in a module or dictionary, then allow runtime settings to be loaded from a python file:

default_options = {'DATABASE': 'sqlite://'}

app = FrescoApp()

# Load default options
app.options.update(default_options)

# Load other options from the file specified in the environment variable
# 'MYAPP_SETTINGS', defaulting to 'settings.py' if unspecified.
app.options.update_from_file(os.environ.get('MYAPP_SETTINGS',
                                            'settings.py'))

You can access configuration options from any point in your application via context.app.options:

from fresco import context

db = connect(context.app.options.DATABASE)

Writing settings.py

Your settings file should be a regular python module containing variable definitions for each configuration option, for example:

DATABASE = 'sqlite:///tmp/myapp.db'
SITENAME = 'myapp.example.com'

Variable names beginning with underscores will be ignored. You can use this feature to avoid polluting your options with unwanted symbols. In this example the ENTROPY option will be available in app.options, but the helper function will not be:

def _read_file(filename):
    with open(filename, 'r') as f:
        return f.read()

ENTROPY = _read_file('conf/.entropy')

As with a regular python module you can use __all__ to specify which variables are loaded from your module.