A common pattern for configuration loading is to use class inheritance to define common settings with production and development overrides, for example,
class Config: DEBUG = False TESTING = False SECRET_KEY = 'secret' class Development(Config): DEBUG = True class Production(Config): SECRET_KEY = 'an actually secret key'
This can then be loaded in say a create_app function, for example:
create_app
def create_app(mode='Development'): """In production create as app = create_app('Production')""" app = Quart(__name__) app.config.from_object(f"config.{mode}") return app
The config_class can be set to a custom class, however it must be changed before the app is initialised as the make_config() is called on construction.
config_class
make_config()
An instance folder is a deployment specific location to store files and configuration settings. As opposed to loading files relative to the app root path open_resource() you can load files relative to an instance path open_instance_resource() including the configuration. To load the configuration from this folder, instead of relative to the app root path simply provide the instance_relative_config argument as True when initialising the app app = Quart(__name__, instance_relative_config=True).
open_resource()
open_instance_resource()
instance_relative_config
True
app = Quart(__name__, instance_relative_config=True)
The instance path can be specified when initialising the app, or found automatically if it exists. The search locations are:
/app.py /instance/
or if the app has been installed:
$PREFIX/var/app-instance/