The request processor dispatches requests to the filesystem, typecasts URL path variables, loads the resource from the filesystem, and then renders and encodes the resource (if it’s dynamic).

class aspen.request_processor.RequestProcessor(**kwargs)

A core request processor designed for integration into a host framework.

The kwargs are for configuration, see DefaultConfiguration for valid keys and default values.


Call the dispatcher and inject the path variables into the given path object.

Parameters:path (Path) – the requested path, e.g. '/foo'
Returns:A DispatchResult object.
process(path, querystring, accept_header, context)

Process a request.

  • path (Path) – the requested path, e.g. Path('/foo')
  • querystring (Querystring) – the query parameters, e.g. Querystring('?bar=baz')
  • accept_header (str) – the value of the HTTP header Accept
  • context (dict) – the context variables passed to dynamic resources

A 3-tuple (dispatch_result, resource, output). The latter two are set to None if dispatching failed.


Given a filesystem path, return a boolean.


Given a filesystem path, return a resource class.


Guess the media type of a file by looking at its extension.

This method is a small wrapper around mimetypes.guess_type(). It returns media_type_default if the guessing fails.

class aspen.request_processor.DefaultConfiguration

Default configuration values.

changes_reload = False

Reload files on every request if they’ve been modified. This can be costly, so it should be turned off in production.

charset_static = None

The charset of your static files. It ends up as a charset= parameter in Content-Type HTTP headers (if the framework on top of Aspen supports that).

dispatcher_class = None

The kind of dispatcher that will be used to route requests to files. By default UserlandDispatcher is used, unless changes_reload is set to True, then HybridDispatcher is used.

encode_output_as = 'UTF-8'

The encoding to use for dynamically-generated output.

indices = ['index.html', 'index.json', 'index', 'index.html.spt', 'index.json.spt', 'index.spt']

List of file names that will be treated as directory indexes. The order matters.

media_type_default = 'text/plain'

If the Content-Type of a response can’t be determined, then this one is used.

media_type_json = 'application/json'

The media type to use for the JSON format.

project_root = None

The root directory of your project.

renderer_default = 'stdlib_percent'

The default renderer for simplates.

resource_directories = []

The list of directories containing resource files. Aspen will refuse to load any resource located outside these directories. The www_root directory is automatically added to this list. The project_root directory is added as well if it exists.

store_static_files_in_ram = False

If set to True, store the contents of static files in RAM.

typecasters = {'float': <function <lambda>>, 'int': <function <lambda>>}

See aspen.request_processor.typecasting.

www_root = None

The root directory of your web app, containing the files it will serve. Defaults to the current directory.