Extended Odoo Client Library with additional functionality
Project description
The Odoo Client Library is a Python3 library to communicate with an Odoo Server using its web services in an user-friendly way. It was created for those that doesn’t want to code XML-RPC calls on the bare metal. It handles XML-RPC as well as JSON-RPC protocol and provides a bunch of syntaxic sugar to make things a lot easier.
Guide
First install the library:
pip install mccann_hub-odoo_client_lib
Now copy-paste the following script describing a simple interaction with an Odoo server:
import mccann_hub.odoolib as odoolib
connection = odoolib.get_connection(hostname="localhost", database="my_db", \
login="my_user", password="xxx")
user_model = connection.get_model("res.users")
ids = user_model.search([("login", "=", "admin")])
user_info = user_model.read(ids[0], ["name"])
print user_info["name"]
# will print "Administrator"
In the previous script, the get_connection() method creates a Connection object that represents a communication channel with authentification to an Odoo server. By default, get_connection() uses XML-RPC, but you can specify it to use JSON-RPC. You can also change the port. Example with a JSON-RPC communication on port 6080:
connection = odoolib.get_connection(hostname="localhost", protocol="jsonrpc", port=6080, ...)
The get_model() method on the Connection object creates a Model object. That object represents a remote model on the Odoo server (for Odoo addon programmers, those are also called osv). Model objects are dynamic proxies, which means you can remotely call methods in a natural way. In the previous script we demonstrate the usage of the search() and read() methods. That scenario is equivalent to the following interaction when you are coding an Odoo addon and this code is executed on the server:
user_osv = self.pool.get('res.users')
ids = user_osv.search(cr, uid, [("login", "=", "admin")])
user_info = user_osv.read(cr, uid, ids[0], ["name"])
Also note that coding using Model objects offer some syntaxic sugar compared to vanilla addon coding:
You don’t have to forward the “cr” and “uid” to all methods.
The read() method automatically sort rows according the order of the ids you gave it to.
The Model objects also provides the search_read() method that combines a search and a read, example:
user_info = user_model.search_read([('login', '=', 'admin')], ["name"])[0]
Here are also some considerations about coding using the Odoo Client Library:
Since you are using remote procedure calls, every call is executed inside its own transaction. So it can be dangerous, for example, to code multiple interdependant row creations. You should consider coding a method inside an Odoo addon for such cases. That way it will be executed on the Odoo server and so it will be transactional.
The browse() method can not be used. That method returns a dynamic proxy that lazy loads the rows’ data from the database. That behavior is not implemented in the Odoo Client Library.
Testing
There is a Docker compose file in the test_containers directory that will stand up a local instance of Odoo:
docker compose -f ./test_containers/compose.yaml up
Compatibility
XML-RPC: OpenERP version 6.1 and superior
JSON-RPC: Odoo version 8.0 (upcoming) and superior
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mccann_hub_odoo_client_lib-2.0.2.tar.gz.
File metadata
- Download URL: mccann_hub_odoo_client_lib-2.0.2.tar.gz
- Upload date:
- Size: 14.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dccdea23fe420634a2b18531e816ed4321bbd5a887a3d01c52c0838f6d8aa409
|
|
| MD5 |
69c50dd03491a767d737385b5beeefa3
|
|
| BLAKE2b-256 |
56b170c23623775eba1c147fccf48f367efbb0aa02b4dc89e293e72292b3a179
|
Provenance
The following attestation bundles were made for mccann_hub_odoo_client_lib-2.0.2.tar.gz:
Publisher:
publish.yml on jabez007/odoo-client-lib
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mccann_hub_odoo_client_lib-2.0.2.tar.gz -
Subject digest:
dccdea23fe420634a2b18531e816ed4321bbd5a887a3d01c52c0838f6d8aa409 - Sigstore transparency entry: 202113512
- Sigstore integration time:
-
Permalink:
jabez007/odoo-client-lib@982344deabd7c659c01d503b0dc7797eee9c6ab4 -
Branch / Tag:
refs/tags/v2.0.2 - Owner: https://github.com/jabez007
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@982344deabd7c659c01d503b0dc7797eee9c6ab4 -
Trigger Event:
release
-
Statement type:
File details
Details for the file mccann_hub_odoo_client_lib-2.0.2-py3-none-any.whl.
File metadata
- Download URL: mccann_hub_odoo_client_lib-2.0.2-py3-none-any.whl
- Upload date:
- Size: 24.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
158ef401716d57d07bdb930d0af018b488b8c943a89eaba85456958b1262fe40
|
|
| MD5 |
35e16d734ddc9c7694eb066eb537d08e
|
|
| BLAKE2b-256 |
53ab19b7e9369e81b205ff5793c8d4a540972c41a09e861624b0f6913b530f70
|
Provenance
The following attestation bundles were made for mccann_hub_odoo_client_lib-2.0.2-py3-none-any.whl:
Publisher:
publish.yml on jabez007/odoo-client-lib
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mccann_hub_odoo_client_lib-2.0.2-py3-none-any.whl -
Subject digest:
158ef401716d57d07bdb930d0af018b488b8c943a89eaba85456958b1262fe40 - Sigstore transparency entry: 202113514
- Sigstore integration time:
-
Permalink:
jabez007/odoo-client-lib@982344deabd7c659c01d503b0dc7797eee9c6ab4 -
Branch / Tag:
refs/tags/v2.0.2 - Owner: https://github.com/jabez007
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@982344deabd7c659c01d503b0dc7797eee9c6ab4 -
Trigger Event:
release
-
Statement type: