QuickStart for people in a hurryΒΆ

You are in a hurry, so we’ll assume you are familiar with Pip ;)

To use Cornice, install it:

$ pip install cornice

To start from scratch, you can use a Cookiecutter project template:

$ pip install cookiecutter
$ cookiecutter gh:Cornices/cookiecutter-cornice

The template creates a working Cornice application.


If you’re familiar with Pyramid and just want to add cornice to an already existing project, you’ll just need to include cornice in your project:


You can then start poking at the file.

For example, let’s define a service where you can GET and POST a value at /values/{value}, where value is an ascii value representing the name of the value.

The views module can look like this:

from cornice import Service

_VALUES = {}

values = Service(name='foo',
                 description="Cornice Demo")

def get_value(request):
    """Returns the value.
    key = request.matchdict['value']
    return _VALUES.get(key)
def set_value(request):
    """Set the value.

    Returns *True* or *False*.
    key = request.matchdict['value']
        # json_body is JSON-decoded variant of the request body
        _VALUES[key] = request.json_body
    except ValueError:
        return False
    return True


By default, Cornice uses a Json renderer.

Run your Cornice application with:

$ pserve project.ini --reload

Set a key-value using Curl:

$ curl -X POST http://localhost:6543/values/foo -d '{"a": 1}'

Check out what is stored in a foo value at http://localhost:6543/values/foo