Application

class tangled.web.app.Application(settings, **extra_settings)[source]

Application container.

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…

Registry:

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.

Settings:

settings can 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:

  • development.ini
  • /some/where/production.ini
  • some.package:some.ini

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 AAppSettings instance instead (typically, but not necessarily, created by calling tangled.web.settings.make_app_settings()).

Extra settings can be passed as keyword args. These settings will override all other settings. They will be parsed along with other settings.

NOTE: If settings is an AppSettings instance, extra settings passed here will be ignored; pass them to the AppSettings instead.

Logging:

If settings are loaded from a file and that file (or one of the files it extends) contains logging config sections (formatters, handlers, loggers), that logging configuration will automatically be loaded via logging.config.fileConfig.

add_helper(helper, name=None, static=False, package=None, replace=False)[source]

Add a “helper” function.

helper can be a string pointing to the helper or the helper itself. If it’s a string, helper and package will be passed to load_object().

Helper functions can be methods that take a Helpers instance 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)[source]

Add a subscriber for the specified event type.

args will be passed to func as keyword args. (Note: this functionality is somewhat esoteric and should perhaps be removed.)

You can also use the subscriber decorator to register subscribers.

get_setting(key, default=NOT_SET)[source]

Get a setting; return default if one is passed.

If key isn’t in settings, try prepending 'tangled.app.'.

If the key isn’t present, return the default if one was passed; if a default wasn’t passed, a KeyError will be raised.

get_settings(settings=None, prefix='tangled.app.', **kwargs)[source]

Get settings with names that start with prefix.

This is a front end for tangled.util.get_items_with_key_prefix() that sets defaults for settings and prefix.

By default, this will get the settings from self.settings that have a 'tangled.app.' prefix.

Alternate settings and/or prefix can be specified.

on_created(func, priority=None, once=True, **args)[source]

Add an ApplicationCreated subscriber.

Sets once to True by default since ApplicationCreated is only emitted once per application.

This can be used as a decorator in the simple case where no args other than func need to be passed along to add_subscriber().