oerplib.rpc

This module provides RPC connectors which use the XML-RPC, Net-RPC or JSON-RPC protocol to communicate with an OpenERP/Odoo server.

Afterwards, RPC services and their associated methods can be accessed dynamically from the connector returned.

XML-RPC and Net-RPC provide the same interface, such as services like db, common or object. On the other hand, JSON-RPC provides a completely different interface, with services provided by Web modules like web/session, web/dataset and so on.

class oerplib.rpc.Connector(server, port=8069, timeout=120, version=None)

Connector base class defining the interface used to interact with a server.

XML-RPC and Net-RPC connectors

class oerplib.rpc.ConnectorXMLRPC(server, port=8069, timeout=120, version=None, scheme='http')

Connector class using the XML-RPC protocol.

>>> from oerplib import rpc
>>> cnt = rpc.ConnectorXMLRPC('localhost', port=8069)

Login and retrieve ID of the user connected:

>>> uid = cnt.common.login('database', 'user', 'passwd')

Execute a query:

>>> res = cnt.object.execute('database', uid, 'passwd', 'res.partner', 'read', [1])

Execute a workflow query:

>>> res = cnt.object.exec_workflow('database', uid, 'passwd', 'sale.order', 'order_confirm', 4)
class oerplib.rpc.ConnectorXMLRPCSSL(server, port=8069, timeout=120, version=None)

Connector class using the XML-RPC protocol over SSL.

class oerplib.rpc.ConnectorNetRPC(server, port=8070, timeout=120, version=None)

Note

No longer available since OpenERP 7.0.

Connector class using the Net-RPC protocol.

static rpc.get_connector(server, port=8069, protocol='xmlrpc', timeout=120, version=None)

Deprecated since version 0.8.

Return a RPC connector to interact with an OpenERP/Odoo server. Supported protocols are:

  • xmlrpc: Standard XML-RPC protocol (default),
  • xmlrpc+ssl: XML-RPC protocol over SSL,
  • netrpc: Net-RPC protocol (no longer available since OpenERP 7.0).

If the version parameter is set to None, the last API supported will be used to send requests to the server. Otherwise, you can force the API to use with the corresponding string version (e.g.: '6.0', '6.1', '7.0', '8.0', ...):

>>> from oerplib import rpc
>>> cnt = rpc.get_connector('localhost', 8069, 'xmlrpc', version='7.0')

JSON-RPC connectors (New in version 0.8)

Warning

The support of JSON-RPC is still in the experimental stage.

class oerplib.rpc.ConnectorJSONRPC(server, port=8069, timeout=120, version=None, deserialize=True)

Connector class using the JSON-RPC protocol.

>>> from oerplib import rpc
>>> cnt = rpc.ConnectorJSONRPC('localhost', port=8069)

Open a user session:

>>> cnt.proxy.web.session.authenticate(db='database', login='admin', password='admin')
{u'jsonrpc': u'2.0', u'id': 202516757,
 u'result': {u'username': u'admin', u'user_context': {u'lang': u'fr_FR', u'tz': u'Europe/Brussels', u'uid': 1},
 u'db': u'test70', u'uid': 1, u'session_id': u'308816f081394a9c803613895b988540'}}

Read data of a partner:

>>> cnt.proxy.web.dataset.call(model='res.partner', method='read', args=[[1]])
{u'jsonrpc': u'2.0', u'id': 454236230,
 u'result': [{u'id': 1, u'comment': False, u'ean13': False, u'property_account_position': False, ...}]}

You can send requests this way too:

>>> cnt.proxy['/web/dataset'].call(model='res.partner', method='read', args=[[1]])
{u'jsonrpc': u'2.0', u'id': 328686288,
 u'result': [{u'id': 1, u'comment': False, u'ean13': False, u'property_account_position': False, ...}]}

Or like this:

>>> cnt.proxy['web']['dataset'].call(model='res.partner', method='read', args=[[1]])
{u'jsonrpc': u'2.0', u'id': 102320639,
 u'result': [{u'id': 1, u'comment': False, u'ean13': False, u'property_account_position': False, ...}]}
class oerplib.rpc.ConnectorJSONRPCSSL(server, port=8069, timeout=120, version=None, deserialize=True)

Connector class using the JSON-RPC protocol over SSL.

>>> from oerplib import rpc
>>> cnt = rpc.ConnectorJSONRPCSSL('localhost', port=8069)

Table Of Contents

Previous topic

oerplib.service.inspect (New in version 0.8)

Next topic

oerplib.tools

This Page