XCAP API

XCAP protocol allows a client to read, write, and modify application configuration data stored in XML format on a server. XCAP maps XML document sub-trees and element attributes to HTTP URIs, so that these components can be directly accessed by clients using HTTP protocol. An XCAP server is used by XCAP clients to store data like buddy lists and presence policy in combination with a SIP Presence server that supports PUBLISH, SUBSCRIBE and NOTIFY methods to provide a complete SIP SIMPLE solution.

XCAP client is implemented by python-xcaplib. The library provides xcaplib.client.XCAPClient class which is an HTTP client with an interface better suited for XCAP servers. The library also provides
a version of XCAPClient (xcaplib.green.XCAPClient) built on top of eventlet, which may be used in twisted reactor.

Components

get(self, application, node=None, etag=None, headers=None)
Make an HTTP GET request to the resource identified by application and node. Return a Resource instance on success.
Raise HTTPError if the operation was unsuccessful.

put(self, application, resource, node=None, etag=None, headers=None)
Make an HTTP PUT request to the resource identified by application and node. Use resource as a request body.
Raise HTTPError is the operation was unsuccessful.

delete(self, application, node=None, etag=None, headers=None)
Make an HTTP DELETE request to the resource identified by application and node.
Raise HTTPError if the operation was unsuccessful.

Usage

client = XCAPClient(xcap_root, xcap_user_id, password=password)
document = file('examples/resource-lists.xml').read()

# put the document on the server
client.put('resource-lists', document)

# read the document from the server
got = client.get('resource-lists')

# get a specific element within a document
element = client.get('resource-lists', '/resource-lists/list/entry/display-name')

# get an attribute:
res = client.get('resource-lists', '/resource-lists/list/entry/@uri')

# replace an element conditionally, based on the etag
client.put('resource-lists', '<entry uri="sip:bob@example.com"><display-name>The Bob</display-name></entry>',
           '/resource-lists/list/entry[@uri="sip:bob@example.com"]', etag=stored_etag)

# delete an element
client.delete('resource-lists', node_selector, etag=res.etag)