The Environment is a container for request handlers, managed objects and other runtime settings as well as the tornado.web.Application settings.

There are two cases where you will need to work with the it: during the bootstrapping phase you may change paths to look for configuration files and you will add the request handlers to the environment. In addition to that you can also use it from within a request handler in and access managed objects, such as HTTP clients that can be used accross a number of client libraries for connection pooling, e.g.

class supercell.environment.Environment

Environment for supercell processes.

add_handler(path, handler_class, init_dict=None, name=None, host_pattern='.*$', cache=None, expires=None)

Add a handler to the tornado.web.Application.

The environment will manage the available request handlers and managed objects. So in the Service.run() method you will add the handlers:

class MyService(s.Service):

    def run():
        self.environment.add_handler('/', Handler)
  • path (str or re.pattern) – The regular expression for the URL path the handler should be bound to.
  • handler_class (supercell.api.RequestHandler) – The request handler class
  • init_dict (dict) – The initialization dict that is passed to the RequestHandler.initialize() method.
  • name (str) – If set the handler and its URL will be available in the RequestHandler.reverse_url() method.
  • host_pattern (str) – A regular expression for matching the hostname the handler will be bound to. By default this will match all hosts (‘.*$’)
  • cache (supercell.api.cache.CacheConfig) – Cache info for GET and HEAD requests to this handler defined by supercell.api.cache.CacheConfig.
  • expires (datetime.timedelta) – Set the Expires header according to the provided timedelta
add_health_check(name, check)

Add a health check to the API.

  • name (str) – The name for the health check to add
  • check (A supercell.api.RequestHandler) – The request handler performing the health check
add_managed_object(name, instance)

Add a managed instance to the environment.

A managed object is identified by a name and you can then access it from the environment as an attribute, so in your request handler you may:

class MyService(s.Service):

    def run(self):
        managed = HeavyObjectFactory.get_heavy_object()
        self.environment.add_managed_object('managed', managed)

class MyHandler(s.RequestHandler):

    def get(self):
  • name (str) – The managed object identifier
  • instance (object) – Some arbitrary instance

The list containing all paths to look for config files.

In order to manipulate the paths looked for configuration files just manipulate this list:

class MyService(s.Service):

    def bootstrap(self):

Determine the configuration file name for the machine this application is running on.

The filenames are generated using a combination of username and machine name. If you deploy the application as user webapp on host fe01.local.dev the configuration name would be webapp_fe01.local.dev.cfg.


Create the tornado application.

Parameters:config – The configuration that will be added to the app

Return the supercell.api.cache.CacheConfig for a certain handler.


Return the timedelta for a specific handler that should define the Expires header for GET and HEAD requests.


Simple property access for health checks.


The dictionary passed to the tornado.web.Application containing all relevant tornado server settings.

Read the Docs v: latest
On Read the Docs
Project Home

Free document hosting provided by Read the Docs.