Binding of CubicWeb connection to Pyramid request.


Enables the core features of Pyramid CubicWeb.

Automatically called by the ‘pyramid’ command, or via config.include('cubicweb.pyramid.code'). In the later case, the following registry entries must be defined first:

A cubicweb ‘config’ instance.
The correponding cubicweb repository.
The vreg.

Context manager to wrap a call to the cubicweb API.

All CW exceptions will be transformed into their pyramid equivalent. When needed, some CW reponse bits may be converted too (mainly headers)

cubicweb.pyramid.core.render_view(request, vid, **kwargs)[source]

Helper function to render a CubicWeb view.

  • request – A pyramid request
  • vid – A CubicWeb view id
  • kwargs – Keyword arguments to select and instanciate the view

The rendered view content

cubicweb.pyramid.core.repo_connect(request, repo, eid)[source]

A lightweight version of cubicweb.server.repository.Repository.connect() that does not keep track of opened sessions, removing the need of closing them

cubicweb.pyramid.core.get_principals(login, request)[source]

Returns the group names of the authenticated user.

This function is meant to be used as an authentication policy callback.

It also pre-open the cubicweb session and put it in request._cw_cached_session for later usage by _cw_session().


If the default authentication policy is not used, make sure this function gets called by the active authentication policy.

  • login – A cubicweb user eid
  • request – A pyramid request

A list of group names

class cubicweb.pyramid.core.CubicWebPyramidRequest(request)[source]

Bases: cubicweb.web.request.ConnectionCubicWebRequestBase

A CubicWeb request that only wraps a pyramid request.

Parameters:request – A pyramid request

returns ‘POST’, ‘GET’, ‘HEAD’, etc.


Returns a ‘<br>’ joined list of the cubicweb current message and the default pyramid flash queue messages.


return the normalized path of the request (ie at least relative to the instance’s root, but some other normalization may be needed so that the returned path may be used to compare to generated urls

Parameters:includeparams – boolean indicating if GET form parameters should be kept in the path

WARNING: we’re intentionally leaving INTERNAL_FIELD_VALUE here

subclasses should overrides to


Obtains a cw session from a pyramid request

Parameters:request – A pyramid request
Returns type:cubicweb.server.session.Session

Not meant for direct use, use request.cw_session instead.


Obtains a cw session from a pyramid request

The connection will be commited or rolled-back in a request finish callback (this is temporary, we should make use of the transaction manager in a later version).

Not meant for direct use, use request.cw_cnx instead.

Parameters:request – A pyramid request
Returns type:cubicweb.server.session.Connection

Obtains a CubicWeb request wrapper for the pyramid request.

Parameters:request – A pyramid request
Returns:A CubicWeb request
Returns type:CubicWebPyramidRequest

Not meant for direct use, use request.cw_request instead.