wuttaweb.app

Application

class wuttaweb.app.WebAppProvider(config)[source]

The app provider for WuttaWeb. This adds some methods to the app handler, which are specific to web apps.

get_web_handler(**kwargs)[source]

Get the configured “web” handler for the app.

Specify a custom handler in your config file like this:

[wutta]
web.handler_spec = poser.web.handler:PoserWebHandler
Returns:

Instance of WebHandler.

wuttaweb.app.main(global_config, **settings)[source]

Make and return the WSGI application, per given settings.

This function is designed to be called via Paste, hence it does require params and therefore can’t be used directly as app factory for general WSGI servers. For the latter see make_wsgi_app() instead.

And this particular function is not even that useful, it only constructs an app with minimal views built-in to WuttaWeb. Most apps will define their own main() function (e.g. as poser.web.app:main), similar to this one but with additional views and other config.

wuttaweb.app.make_asgi_app(main_app=None, config=None)[source]

Make and return a ASGI app, using the given Paste app factory.

This works the same as make_wsgi_app() and should be called in the same way etc.

wuttaweb.app.make_pyramid_config(settings)[source]

Make and return a Pyramid config object from the given settings.

The config is initialized with certain features deemed useful for all apps.

Returns:

Instance of pyramid.config.Configurator.

wuttaweb.app.make_wsgi_app(main_app=None, config=None)[source]

Make and return a WSGI app, using the given Paste app factory.

See also make_asgi_app() for the ASGI equivalent.

This function could be used directly for general WSGI servers (e.g. uvicorn), *if* you just want the built-in main() app factory.

But most likely you do not, in which case you must define your own function and call this one with your preferred app factory:

from wuttaweb.app import make_wsgi_app

def my_main(global_config, **settings):
    # TODO: build your app
    pass

def make_my_wsgi_app():
    return make_wsgi_app(my_main)

So make_my_wsgi_app() could then be used as-is for general WSGI servers. However, note that this approach will require setting the WUTTA_CONFIG_FILES environment variable, unless running via wutta webapp.

Parameters:
  • main_app – Either a Paste-compatible app factory, or spec for one. If not specified, the built-in main() is assumed.

  • config – Optional config object. If not specified, one is created based on WUTTA_CONFIG_FILES environment variable.

wuttaweb.app.make_wutta_config(settings, config_maker=None, **kwargs)[source]

Make a WuttaConfig object from the given settings.

Note that settings dict will (typically) correspond to the [app:main] section of your config file.

Regardless, the settings must contain a special key/value which is needed to identify the location of the config file. Assuming the typical scenario then, your config file should have an entry like this:

[app:main]
wutta.config = %(__file__)s

The %(__file__)s is auto-replaced with the config file path, so ultimately settings would contain something like (at minimum):

{'wutta.config': '/path/to/config/file'}

If this config file path cannot be discovered, an error is raised.