class cubes.wsme.types.PassThroughType[source]

Special webservice type that transmit a value without doing anything

It is used in wsme signature for the ‘entity’ argument which is passed by the controller itself and should not be transtyped in any way.

cubes.wsme.types.JsonData = <cubes.wsme.types.JsonDataType object>

User type that carry json encoded arbitrary data.

cubes.wsme.types.binary = <cubes.wsme.types.BinaryType object>

webservice type that map the cubicweb.Binary values.

class cubes.wsme.types.wsattr(rtype=None, role='subject', etype=None, datatype=None, writeonly=False, **kw)[source]

Cubicweb-specific version of wsme.types.wsattr

To be used on a Base class. All the attributes are optionnal and can be deduced from the rtype.


The corresponding relation in the model


The role of the parent class in the relation


The entity type on the other side of the relation


The webservice type


returns True if an object is a wsattr

class cubes.wsme.types.Base(entity=None, keyonly=False, fetch=())[source]

Bases: wsme.types.Base

Base class for a complex type that map an entity type


Entity eid

alias of long


Returns a dict with all the attribute values.

This dict can be used to feed cubicweb.entity.Entity.cw_set().

classmethod finalize_init()[source]

Finalize the class initialization.

This last step resolve types in the underlying attributes.

from_entity(entity, keyonly=False, fetch=())[source]

Load values from an entity

  • entity – the entity
  • keyonly – if True, only the .eid and .modfication_date will be loaded. The result can be used as “timestamped reference”.
  • fetch – a list of relations to eager load. Unless specified, all the ‘1’ or ‘?’ relation targets will be loaded as ‘keyonly’, and the ‘*’ or ‘+’ relations will not be loaded at all.
classmethod reginit(vreg)[source]

Register the class

Use the informations in the registry, and most notably the schema, to initialize the attributes.


Update the entity attributes (not the non-final relations).

class cubes.wsme.types.Any(entity=None, keyonly=False, fetch=())[source]

Complex type to carry any type of entity.

Automatically used for polymorphic relations targets

cubes.wsme.types.scan(vreg, modname)[source]

Scan a module for any class inheriting Base and register them.


‘webservice’ controller implementation

class cubes.wsme.controller.WSController(*args, **kwargs)[source]

Bases: cubicweb.web.controller.Controller

A controller that rely on WSME to provide webservice API for an entity.


Main entry-point of the controller.

Will dispatch the request to the adequate function depending on the http method and the form/rset content.

It also takes care of converting the inputs (form & body) to call arguments using the WSME api, based on the function signatures.

The following form values are used, which are normaly set by cubes.wsme.views.RestPathEvaluator:

  • _ws_method: the HTTP method
  • _ws_etype: the etype (ignored, only used by the selector)
  • _ws_rtype: the relation type if provided
  • _ws_rtype_target: An option relation target id

If the :arg:`rset` contains an entity, it will be considered as the target of the API call.

classmethod resolve_types(registry)[source]

Late-resolve the types of the function signatures.

This function is called at regitering time (by __registered__()).

class cubes.wsme.controller.WSCRUDController(*args, **kwargs)[source]

Bases: cubes.wsme.controller.WSController

An entity type CRUD controller

The displatch is summarized in this table, where ‘entity’ means that an entity exists in the rset:

form-rset / verb GET POST PUT DELETE
  _get() _post()    
entity _entity_get()   _entity_put() _entity_delete()
entity, _ws_rtype _entity_rtype_get() _entity_rtype_post()    
entity, _ws_rtype, _ws_rtype_target       _entity_rtype_target_delete()

Create an entity from ws data


Default implementation of DELETE /etype/eid.

_entity_get(entity, fetch=[])[source]

Default implementation of GET /etype/eid.

_entity_put(entity, fetch=[], data=None)[source]

Default implementation of PUT /etype/eid.

_entity_rtype_get(entity, rtype, orderby=None, limit=None, offset=None, keyonly=False)[source]

Default implementation of GET /etype/eid/rtype.

_entity_rtype_post(entity, rtype, eid)[source]

Default implementation of POST /etype/eid/rtype.

_entity_rtype_target_delete(entity, rtype, eid)[source]

Default implementation of DELETE /etype/eid/rtype/eid.

_get(orderby=None, filter=None, limit=0, offset=0, fetch=[], keyonly=False)[source]

List entities with an optional filter.

Default implementation of GET /etype.

  • filter
  • fetch – A list of relations and subrelations of which the target entities will be returned.

Get a list of entities from a list a webservice data


Get an entity and update/create it and its related entities all along.

Parameters:data – A webservice type instance

Handle webservice data.

It returns a tuple (eid, values, relation_values), where eid can be None if the data had none, values contains the final and inlined values, and relation_values the relation values. These variables are dictionnaries that can be fed cw_set().

While handling the entity data, the related entities present in the data will be updated/create (via _get_entity()).

_post(fetch=[], keyonly=False, data=None)[source]

Default implementation of POST /etype.


Update an existing entity from ws data