ERPpeek is a versatile tool that can be used both as an interactive Command-line Interface (CLI) and as a Python library, with a more convenient API than the one provided by xmlrpclib
. It is available from the PyPi index and can be installed with the following:
$ pip install -U erppeek
On a Unix system, if you are installing it system wide, you might need to prepend sudo
to the command.
The ERPpeek
library provides a programming interface, wrapping around xmlrpclib
, which is similar to the programming interface we have for the server-side code.
Our point here is to provide a glimpse of what the ERPpeek
library has to offer, and not to provide a full explanation of all its features.
We can start by reproducing our first steps with xmlrpclib
using the erppeek
as follows:
>>> import erppeek >>> api = erppeek.Client('http://localhost:8069', 'todo','admin', 'admin') >>> api.common.version() >>> api.count('res.partner', []) >>> api.search('res.partner', [('country_id', '=', 'be'), ('parent_id', '!=', False)]) >>> api.read('res.partner', [44], ['id', 'name', 'parent_id'])
As you can see, the API calls use fewer arguments and are similar to the server-side counterparts.
But ERPpeek
doesn't stops here, and also provides a representation for models. We have the following two alternative ways to get an instance for a model, either using the model()
method or accessing it as a camel case attribute name:
>>> m = api.model('res.partner') >>> m = api.ResPartner
Now we can perform actions on that model as follows:
>>> m.count([('name', 'like', 'Packt%')]) 1 >>> m.search([('name', 'like', 'Packt%')]) [44]
It also provides client-side object representation for records as follows:
>>> recs = m.browse([('name', 'like', 'Packt%')]) >>> recs <RecordList 'res.partner,[44]'> >>> recs.name ['Packt Publishing']
As you can see, erppeek
library goes a long way from plain xmlrpclib
, and makes it possible to write code that can be reused server side with little or no modification.
Not only can erppeek
library be used as a Python library, it is also a CLI that can be used to perform administrative actions on the server. Where the odoo shell
command provided a local interactive session on the host server, erppeek
library provides a remote interactive session on a client across the network.
Opening a command line, we can have a peek at the options available, as shown in the following:
$ erppeek --help
Let's see a sample session as follows:
$ erppeek --server='http://localhost:8069' -d todo -u admin Usage (some commands): models(name) # List models matching pattern model(name) # Return a Model instance (...) Password for 'admin': Logged in as 'admin' todo >>> model('res.users').count() 3 todo >>> rec = model('res.partner').browse(43) todo >>> rec.name 'Packt Publishing'
As you can see, a connection was made to the server, and the execution context provided a reference to the model()
method to get model instances and perform actions on them.
The erppeek.Client
instance used for the connection is also available through the client
variable.
Notably, it provides an alternative to the web client to manage the add-on modules installed:
client.modules()
: lists modules available or installedclient.install()
: performs module installationclient.upgrade()
: performs module upgradesclient.uninstall()
: uninstalls modulesSo, erppeek
can also provide good service as a remote administration tool for Odoo servers.