class flask.ext.pushrod.Pushrod(app=None, renderers=('json', 'jinja2'), default_renderer='html')

The main resolver class for Pushrod.

Parameters:renderers – A tuple of renderers that are registered immediately (can also be strings, which are currently expanded to flask.ext.pushrod.renderers.%s_renderer)
app = None

The current app, only set from the constructor, not if using init_app().

format_arg_name = 'format'

The query string argument checked for an explicit renderer (to override header-based content type negotiation).


This is set on the class level, not the instance level.


Inspects a Flask Request for hints regarding what renderer to use.

Parameters:request – The request to be inspected (defaults to flask.request)
Returns:List of matching renderers, in order of user preference

Registers the Pushrod resolver with the Flask app (can also be done by passing the app to the constructor).


Gets the logger to use, mainly for internal use.

The current resolution order looks as follows:

mime_type_renderers = None

The renderers keyed by MIME type.

named_renderers = None

The renderers keyed by output format name (such as html).


Runs an object through the normalizer mechanism, with the goal of producing a value consisting only of “native types” (unicode, int, long, float, dict, list, etc).

The resolution order looks like this:

See Bundled Normalizers for all default normalizers.

Parameters:obj – The object to normalize.
normalizer_overrides = None

Hooks for overriding a class’ normalizer, even if they explicitly define one.

All items should be lists of callables. All values default to an empty list.

normalizers = None

Hooks for providing a class with a fallback normalizer, which is called only if it doesn’t define one. All items should be callables.

register_renderer(renderer, default=False)

Registers a renderer with the Pushrod resolver (can also be done by passing the renderer to the constructor).

render_response(response, renderer=None, renderer_kwargs=None)

Renders an unrendered response (a bare value, a (response, status, headers)-tuple, or an UnrenderedResponse object).

Throws RendererNotFound:

If a usable renderer could not be found (explicit renderer argument points to an invalid render, or no acceptable mime types can be used as targets and there is no default renderer)

  • response – The response to render
  • renderer – The renderer(s) to use (defaults to using get_renderer_for_request())
  • renderer_kwargs – Any extra arguments to pass to the renderer


For convenience, a bare string (unicode, str, or any other basestring derivative), or a derivative of werkzeug.wrappers.BaseResponse (such as flask.Response) is passed through unchanged.


A renderer may mark itself as unable to render a specific response by returning None, in which case the next possible renderer is attempted.



Decorator that wraps view functions and renders their responses through flask.ext.pushrod.Pushrod.render_response().


Views should only return dicts or a type that normalizes down to dicts.

Parameters:renderer_kwargs – Any extra arguments to pass to the renderer


flask.ext.pushrod.renderers.renderer(name=None, mime_type=None, normalize=True)

Flags a function as a Pushrod renderer.


Before it is recognized by flask.ext.pushrod.Pushrod.get_renderers_for_request() (and, by extension, render_response()) it must be registered to the app’s Pushrod instance (using register_renderer(), or passed as part of the renderers argument to the Pushrod constructor).

  • name – A basestring or a tuple of basestrings to match against when explicitly requested in the query string
  • mime_type – A basestring or a tuple of basestrings to match against against when using HTTP content negotiation
  • normalize – If True then the unrendered response will be passed through flask.ext.pushrod.Pushrod.normalize()
class flask.ext.pushrod.renderers.UnrenderedResponse(response=None, status=None, headers=None)

Holds basic response data from the view function until it is processed by the renderer.

rendered(rendered_response, mime_type)

Constructs a rendered_class (flask.Response by default) based on the response parameters.


The class to construct with the rendered response, defaults to flask.Response.

alias of Response

Bundled Renderers

flask.ext.pushrod.renderers.json_renderer(unrendered, **kwargs)

Renders a response using json.dumps().

Renderer MIME type triggers:
  • application/json
Renderer name triggers:
  • json
flask.ext.pushrod.renderers.jinja2_renderer(unrendered, **kwargs)

Renders a response using flask.render_template().

Renderer MIME type triggers:
  • text/html
Renderer name triggers:
  • html

Bundled Normalizers

Flask-Pushrod ships with a few normalizers by default. For more info, see normalize().

Flask-Pushrod’s built-in normalizers are generally named with the scheme normalize_type.


Normalizers also apply to subclasses, unless the subclass defines another normalizer.

flask.ext.pushrod.normalizers.normalize_basestring(x, pushrod)[source]
Takes :


flask.ext.pushrod.normalizers.normalize_iterable(x, pushrod)[source]
Takes :

list with all values normalized

flask.ext.pushrod.normalizers.normalize_dict(x, pushrod)[source]
Takes :dict
Returns:dict with all keys converted to unicode and then normalized and all values normalized
flask.ext.pushrod.normalizers.normalize_int(x, pushrod)[source]
Takes :

int or long

flask.ext.pushrod.normalizers.normalize_float(x, pushrod)[source]
Takes :float
flask.ext.pushrod.normalizers.normalize_bool(x, pushrod)[source]
Takes :bool
flask.ext.pushrod.normalizers.normalize_none(x, pushrod)[source]
Takes :None
flask.ext.pushrod.normalizers.normalize_object(x, pushrod)[source]

Delegates normalization to the object itself, looking for the following attributes/methods (in this order):

  • __pushrod_normalize__ - Essentially treated as if a normalizer was explicitly registered
  • __pushrod_fields__ - A list of names fields, which is essentially treated like {k: getattr(x, k) for k in x.__pushrod_fields__}
  • __pushrod_field__ - A name of a single field, x is then substituted for what is (simplified) getattr(x, x.__pushrod_field)


__pushrod_fields__ and __pushrod_field__ can be either a callable or an attribute, while __pushrod_normalize__ must be a callable.

Takes :object


exception flask.ext.pushrod.renderers.RendererNotFound

Thrown when no acceptable renderer can be found, see flask.ext.pushrod.Pushrod.get_renderers_for_request().


This class inherits from werkzeug.exceptions.NotAcceptable, so it’s automatically converted to 406 Not Acceptable by Werkzeug if not explicitly handled (which is usually the intended behaviour).

Table Of Contents

Related Topics

This Page

Fork me on GitHub