Reference

Router Class

class styrofoam.Router(default_app=None, apps=None)[source]

This implements the main WSGI app and is the central object. It holds Application objects and can be called as a WSGI app.

Parameters:
  • default_app – The default app that is mounted at '/' (technically it’s mounted at ''). This must be a function, not an Application object.
  • apps – A list of Application objects that will be used as the initial value of the apps property. A tuple should not be used. Default value is an empty list.
add_app(*args)[source]

Adds a WSGI application to the router. The attributes passed to this method are passed to Application.__init__, so these two are the same:

my_router.apps.append(Application(func=f, url='/hi'))
my_router.add_app(func=f, url='/hi')

Application Class

class styrofoam.Application(func, url, modify_urls=False)[source]

This class represents a WSGI application. It holds the WSGI handler function of the app, the url prefix that the app is mounted at, and some other configuration options. A Router object holds an array of Application objects, along with the default WSGI application.

Parameters:
  • func – The WSGI handler function (the one with the environ and the start_request arguments)
  • url – The url to mount the application at. It must have a beginning forward slash, but must not have one at the end (e.g. /path/to/app).
  • modify_urls – Whether or not to parse the app’s output and correct urls in it (e.g. in an <a> tag) to go to urls within the one the app is mounted at. For example, an application that is mounted at /oof will have <a href="/no"> replaced to <a href="/oof/no">. It currently supports HTTP headers and HTML.