Odoopyter is a minimal Jupyter notebook for interactive work with the Odoo ORM (via env) directly from Python.
- Brings up the Odoo Registry and ORM Environment in Jupyter.
- Provides ready-to-use variables:
registry— model registrycr— DB cursor (transaction)env— Odoo Environment (ORM)env_user— current user (env.user)
Odoo.ipynb— main notebook.odoo_init.py— bootstrap script that initializesregistry/cr/env/env_user.odoo.conf— example/local copy of the Odoo configuration.
- In
Odoo.ipynb, the bootstrap script is executed via%run. - The script:
- adds the Odoo path to
sys.path - reads the
odoo.confconfiguration - creates
registryand openscr - creates
envandenv_user
- adds the Odoo path to
- After that, you can execute any ORM operations via
env['model']....
Connection parameters are defined as constants in odoo_init.py:
ODOO_PATH— path to the Odoo directory (where theodoopackage is located).DB_NAME— database name.ODOO_CONFIG_PATH— path to the Odoo configuration.
In the notebook, it is recommended to run the script using a relative path (if Odoo.ipynb and odoo_init.py are in the same directory):
%run ./odoo_init.pyYou work directly with a transaction via cr.
cr.commit()— persists changes.cr.rollback()— rolls back changes.
If you are experimenting, it is recommended to use rollback() first.
print("User:", env_user.name, "| Company:", env_user.company_id.name)
partners = env["res.partner"].search([], limit=5, order="id desc")
print("Partners:", partners.mapped("display_name"))
print("Installed modules:", env["ir.module.module"].search_count([("state", "=", "installed")]))