How to Connect an Odoo Server with Python Client Lib
By Braincuber Team
Published on February 5, 2026
Integrating external applications with your Odoo ERP is a common requirement for growing businesses. Whether you are building a custom mobile app for field service agents or syncing data with a legacy warehouse system, you need a reliable way to talk to Odoo's backend.
While Odoo provides a standard XML-RPC interface, writing raw XML-RPC calls can be tedious and error-prone. Enter odoo-client-lib, a Python wrapper that makes connecting to Odoo as simple as working with local objects. In this guide, we'll demonstrate how MegaMart Retail uses this library to sync customer data from their external loyalty portal.
What You'll Learn:
- Installation: Setting up the environment.
- Connection: Authenticating via JSON-RPC or XML-RPC.
- Data Operations: Reading and searching records efficiently.
Step 1: Installation
First, ensure you have Python 3 installed. Then, install the library using pip:
pip install odoo-client-lib
Step 2: Connecting to Your Odoo Instance
Here is a complete Python script that connects to MegaMart's Odoo server, searches for a specific customer, and retrieves their balance.
import odoolib
class MegaMartSync:
def __init__(self, connection):
self.connection = connection
def get_customer_balance(self, email):
"""
Connects to 'res.partner' model and fetches the
total invoiced amount (credit) for a user.
"""
partner_model = self.connection.get_model('res.partner')
# 1. Search for the partner ID
partner_ids = partner_model.search([('email', '=', email)])
if not partner_ids:
return None
# 2. Read specific fields for the found ID
# Note: 'credit' usually represents receivables in Odoo
records = partner_model.read(partner_ids, ['name', 'credit'])
return records[0]
# Configuration for MegaMart Production Server
# You can switch protocol to 'xmlrpc' if preferred
connection = odoolib.get_connection(
hostname="odoo.megamart.com",
database="megamart_prod",
login="api_user",
password="super_secure_password",
protocol="jsonrpc",
port=443
)
# Initialize Sync Logic
sync_tool = MegaMartSync(connection)
customer_data = sync_tool.get_customer_balance('john.doe@example.com')
print(f"Customer: {customer_data['name']}")
print(f"Outstanding Balance: ${customer_data['credit']}")
Why Use odoo-client-lib?
Comparing raw XML-RPC with this library highlights why developers prefer the wrapper approach:
| Feature | Raw XML-RPC | odoo-client-lib |
|---|---|---|
| Authentication | Send UID & Password every call | Handled automatically |
| Syntax | Verbose lists of arguments | Pythonic (e.g., model.search()) |
| Pipelines | Manual chaining | Supports search_read() easily |
Important Limitations
- No Browse Method: Unlike server-side code, you cannot use
browse()to navigate records via dot notation (e.g.,partner.company_id.namewon't work). You must useread()for specific fields. - Transactions: Each API call is its own transaction. If you need 5 operations to happen atomically (all or nothing), you should write a custom controller functionality in Odoo instead of chaining 5 client API calls.
Conclusion
Using odoo-client-lib drastically reduces the friction of connecting external Python applications to Odoo. For MegaMart, this meant their loyalty sync script took 20 lines of code instead of 100, making it easier to maintain and debug.
Building an Odoo Integration?
Our team can help you design secure, high-performance API integrations for your mobile apps and third-party services.
