Skip to content

About

API client to integrate with the Odoo web services from Python

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

86 Commits

Folders and files

Repository files navigation

Odoo API Client Python

API client to integrate with the Odoo web services from Python.

pip install odoo-api-client

Requires Python 3.13 or newer; tested on 3.13, 3.14 and 3.15. The package is imported as odoo_api_client and has no dependencies.

Odoo authentication

The simplest and recommended option is to set the Odoo API credentials in environment variables. The API client reads them automatically.

export ODOO_API_HOST="api-host-odoo"
export ODOO_API_DATABASE="api-name-database-odoo"
export ODOO_API_USER="api-user-odoo"
export ODOO_API_PASSWORD="api-password-odoo"

Without environment variables, the credentials must be given when creating the objects. Example with the generic client:

from odoo_api_client import ApiClient
ODOO_API_HOST="api-host-odoo"
ODOO_API_DATABASE="api-name-database-odoo"
ODOO_API_USER="api-user-odoo"
ODOO_API_PASSWORD="api-password-odoo"
client = ApiClient(ODOO_API_HOST, ODOO_API_DATABASE, ODOO_API_USER, ODOO_API_PASSWORD)

Example with the specific client for HelpdeskTicket:

from odoo_api_client.models.helpdesk.helpdesk_ticket import HelpdeskTicket
ODOO_API_HOST="api-host-odoo"
ODOO_API_DATABASE="api-name-database-odoo"
ODOO_API_USER="api-user-odoo"
ODOO_API_PASSWORD="api-password-odoo"
helpdesk_ticket_client = HelpdeskTicket(ODOO_API_HOST, ODOO_API_DATABASE, ODOO_API_USER, ODOO_API_PASSWORD)

Errors

Client errors are raised as OdooApiError, which has the message (message) and, when Odoo provides it, the error code (code).

from odoo_api_client import OdooApiError

try:
    client.client_execute_kw('res.partner', 'read', domains=[5])
except OdooApiError as e:
    print(e.code, e.message)

Development

The project configuration, its dependencies and the development tools are in pyproject.toml. Create the venv virtual environment with the newest Python, 3.15 (any supported version works):

make PYTHON=python3.15 install-dev

If a venv with another Python version already exists, remove it first (rm -rf venv), because the Makefile does not recreate an existing environment.

Checks (CI runs make check and make docs on Python 3.13, 3.14 and 3.15):

make check      # lint + typecheck + tests
make lint       # ruff check
make typecheck  # mypy and pyright in strict mode
make tests      # unit tests with a minimum coverage of 95%

The unit tests (tests/unit) use a fake Odoo, with no connection.

The integration tests (tests/integration) run against a real Odoo and create and modify data in it. They use the variables in tests/test.env (copy it from tests/test.env-dist) and are not run by make tests:

make tests-integration

To build the documentation with Sphinx:

make docs

The .rst files in docs/ are kept by hand: a new package needs its own page, listed in the page of its parent package. make docs fails on any Sphinx warning, so a missing page or a broken reference is reported.

About

API client to integrate with the Odoo web services from Python

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Contributors

Languages