This module provides RPC connectors which use the XML-RPC, Net-RPC or JSON-RPC protocol to communicate with an OpenERP 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 of OpenERP like web/session, web/dataset and so on.
Connector base class defining the interface used to interact with an OpenERP server.
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)
Connector class using the XML-RPC protocol over SSL.
Note
No longer available since OpenERP 7.0.
Connector class using the Net-RPC protocol.
Deprecated since version 0.8.
Return a RPC connector to interact with an OpenERP server. Supported protocols are:
- xmlrpc: Standard XML-RPC protocol (default),
- xmlrpc+ssl: XML-RPC protocol over SSL,
- netrpc: Net-RPC protocol made by OpenERP (no longer available since OpenERP v7.0).
If the version parameter is set to None, the last API supported will be used to send requests to OpenERP. Otherwise, you can force the API to use with the corresponding string version (e.g.: '6.0', '6.1', '7.0', ...):
>>> from oerplib import rpc
>>> cnt = rpc.get_connector('localhost', 8069, 'xmlrpc', version='7.0')
Warning
The support of JSON-RPC is still in the experimental stage.
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, ...}]}
Connector class using the JSON-RPC protocol over SSL.
>>> from oerplib import rpc
>>> cnt = rpc.ConnectorJSONRPCSSL('localhost', port=8069)