tet.config package

Application configuration utilities for Tet.

This module provides the main entry points for creating Tet applications:

Features

Tet supports the following features that can be selectively included:

  • services - Dependency injection via pyramid_di

  • i18n - Internationalization support

  • renderers.json - JSON rendering with custom type adapters

  • renderers.tonnikala - Tonnikala template engine integration

  • renderers.tonnikala.i18n - Tonnikala with i18n support

  • security.authorization - Custom authorization policy

  • security.csrf - CSRF token protection

Example

Using the application_factory decorator:

from tet.config import application_factory, ALL_FEATURES

@application_factory(included_features=ALL_FEATURES)
def main(config):
    config.add_route('home', '/')
    config.scan()

Using create_configurator directly:

from tet.config import create_configurator, ALL_FEATURES

def main(global_config, **settings):
    config = create_configurator(
        global_config=global_config,
        settings=settings,
        included_features=ALL_FEATURES,
    )
    config.add_route('home', '/')
    config.scan()
    return config.make_wsgi_app()
tet.config.application_factory(factory_function: Callable[[Configurator], Any] = None, configure_only=False, included_features=[], excluded_features=(), package=None, **extra_parameters)[source]

A decorator for main method / application configurator for Tet.

The wrapped function must accept a single argument - the Configurator. The wrapper itself accepts arguments (global_config, **settings) like an ordinary Pyramid/Paster application entry point does.

If configure_only=False (the default), then the return value is a WSGI application created from the configurator.

included_features contains an iterable of features that should be automatically included in the application. By default all standard Tet features are included. For maximal future compatibility you can specify the included feature names here.

excluded_features should be an iterable of features that shouldn’t be automatically included - this serves as a fast way to get all standard features except a named few.

package should be the package passed to the Configurator object; otherwise the package of the caller is assumed.

Parameters:
  • factory_function – The actual wrapped factory function that accepts parameter (config: Configurator)

  • configure_only – True if no WSGI application is to be made, false to actually create the WSGI application as the return value

  • included_features – The iterable of included features. This can in turn contain other iterables; they are flattened by the wrapper into a list of strings.

  • excluded_features – The iterable of excluded features. This can in turn contain other iterables; they are flattened by the wrapper into a list of strings.

  • extra_parameters – extra parameters that will be passed as-is to the actual configurator generation.

Returns:

the WSGI app if configure_only is False; config, if configure_only is True.

tet.config.create_configurator(*, global_config=None, settings=None, merge_global_config=True, configurator_class=<class 'pyramid.config.Configurator'>, included_features=(), excluded_features=(), package=None, **kw) Configurator[source]

Create a Pyramid Configurator with Tet features.

Parameters:
  • global_config – Global configuration dict (from PasteDeploy)

  • settings – Application settings dict

  • merge_global_config – If True, merge global_config into settings

  • configurator_class – Configurator class to use

  • included_features – Tet features to include (see ALL_FEATURES)

  • excluded_features – Tet features to exclude

  • package – Package for the configurator (defaults to caller’s package)

  • kw – Additional arguments passed to the Configurator

Returns:

Configured Pyramid Configurator instance