The application container handles configuration and provides the WSGI interface. It is passed to components such as handlers, requests, and resources so they can inspect settings, retrieve items from the registry, etc…
Speaking of which, the application instance acts as a registry (it’s a subclass of
tangled.registry.Registry). This provides a means for extensions and application code to set application level globals.
settingscan be passed as either a file name pointing to a settings file or as a dict.
File names can be specified as absolute, relative, or asset paths:
A plain dict can be used when no special handling of settings is required. For more control of how settings are parsed (or to disable parsing), pass a
AAppSettingsinstance instead (typically, but not necessarily, created by calling
Extra settings can be passed as keyword args. These settings will override all other settings. They will be parsed along with other settings.
AppSettingsinstance, extra settings passed here will be ignored; pass them to the
If settings are loaded from a file and that file (or one of the files it extends) contains logging config sections (
loggers), that logging configuration will automatically be loaded via
add_helper(helper, name=None, static=False, package=None, replace=False)¶
Add a “helper” function.
helpercan be a string pointing to the helper or the helper itself. If it’s a string,
packagewill be passed to
Helper functions can be methods that take a
Helpersinstance as their first arg or they can be static methods. The latter is useful for adding third party functions as helpers.
Helper functions can be accessed via
request.helpers. The advantage of this is that helpers added as method have access to the application and the current request.
add_subscriber(event_type, func, priority=None, once=False, **args)¶
Add a subscriber for the specified event type.
argswill be passed to
funcas keyword args. (Note: this functionality is somewhat esoteric and should perhaps be removed.)
You can also use the
subscriberdecorator to register subscribers.
Get a setting; return
defaultif one is passed.
keyisn’t in settings, try prepending
keyisn’t present, return the
defaultif one was passed; if a
defaultwasn’t passed, a KeyError will be raised.
get_settings(settings=None, prefix='tangled.app.', **kwargs)¶
Get settings with names that start with
This is a front end for
tangled.util.get_items_with_key_prefix()that sets defaults for
By default, this will get the settings from
self.settingsthat have a
prefixcan be specified.
on_created(func, priority=None, once=True, **args)¶
Trueby default since
ApplicationCreatedis only emitted once per application.
This can be used as a decorator in the simple case where no args other than
funcneed to be passed along to