This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

Smart, simple content negotiation for Python web applications.

Content negotiation can be difficult to do well. Ideally, your code should be DRY, and you wouldn’t be repeating the same old boilerplate in multiple view methods in order to emit the same domain object in different formats. negotiate helps make your life even easier by allowing you to decorate your view methods with formatters that automatically translate your domain objects into the format requested by the client.

It’s really simple to use. Hopefully this example (for a Flask application) makes the main points clear:

# First, we write a couple of formatters that specify how to translate the
# output of the view function into a particular format. Here we define a
# JSON formatter and an HTML formatter that takes a template parameter.

from negotiate.flask import Formatter

class JSONFormatter(Formatter):
    format = 'json'
    mimetypes = ['application/json']

    def render(self, obj):
        return json.dumps(obj)

class HTMLFormatter(Formatter):
    format = 'json'
    mimetypes = ['text/html']

    def configure(self, template):
        self.template = template

    def render(self, obj):
        return render(self.template, **obj)

# Then, when building the application, we decorate the view function with the
# "negotiate" decorator, listing the formats in which this view is available.

from negotiate.flask import negotiate

@negotiate(HTMLFormatter, template='post.html')
def view_post(id, format=None):
    post = Posts.by_id(id)

    if post is None:
    if not g.user.authorize('read', post):

    return {'post': post}

The result is a view action that will return an HTML version of the post by default (i.e. with Accept: */* and no explicit format), or if the .html extension is explicitly specified, or a JSON version of the post if the .json extension is given or Accept: application/json is sent with the request.


negotiate currently supports Flask and Pylons, although adding support for other web frameworks should be pretty easy. Have a look at negotiate/ and negotiate/ to see the small amount of integration code required.

Release History

Release History


This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
negotiate-0.0.1.tar.gz (4.9 kB) Copy SHA256 Checksum SHA256 Source Apr 2, 2012

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting