Cliquet maps URLs and permissions to resources using ViewSets.

View sets can be viewed as a set of rules which can be applied to a resource in order to define what should be inserted in the routing mechanism of pyramid.

Configuring a viewset

To use Cliquet in a basic fashion, there is not need to understand how viewsets work in full detail, but it might be useful to know how to extend the defaults.

Default viewset can be extended by passing viewset arguments to the resource.register class decorator:

from cliquet import resource

class Resource(resource.BaseResource):
    mapping = BookmarkSchema()

Subclassing a viewset

In case this isn’t enough to update the default properties, the default ViewSet class can be subclassed in a more specific viewset, and then be passed during the registration phase:

from cliquet import resource

class MyViewSet(resource.ViewSet):

    def get_service_name(self, endpoint_type, resource):
        """Returns the name of the service, depending a given type and
        # Get the resource name from an akwards location.
        return name

class Resource(resource.BaseResource):
    mapping = BookmarkSchema()

ViewSet class

In order to customize the resource URLs or permissions, the viewset class can be extended:

class cliquet.resource.ViewSet(**kwargs)

The default ViewSet object.

A viewset contains all the information needed to register any resource in the Cornice registry.

It provides the same features as cornice.resource(), except that it is much more flexible and extensible.


Update viewset attributes with provided values.

get_view_arguments(endpoint_type, resource, method)

Return the Pyramid/Cornice view arguments for the given endpoint type and method.

  • endpoint_type (str) – either “collection” or “record”.
  • resource – the resource object.
  • method (str) – the HTTP method.
get_record_schema(resource, method)

Return the Cornice schema for the given method.

get_view(endpoint_type, method)

Return the view method name located on the resource object, for the given type and method.

  • For collections, this will be “collection_{method|lower}
  • For records, this will be “{method|lower}.

Returns the name of the resource.

get_service_name(endpoint_type, resource)

Returns the name of the service, depending a given type and resource.

is_endpoint_enabled(endpoint_type, resource_name, method, settings)

Returns if the given endpoint is enabled or not.

Uses the settings to tell so.