Local Development Server
Relevant source files
The following files were used as context for generating this wiki page:
The Local Development Server environment for OdooConnectorAPI is designed to provide a RESTful interface using FastAPI to interact with an Odoo ERP instance. It supports two primary modes of local operation: a direct Python-based execution using Uvicorn and a containerized approach using Docker Compose. The environment facilitates asynchronous communication with Odoo via the odoorpc library, allowing developers to test endpoints and integration logic locally before deployment.
Sources: README.md:3-8, app/main.py:1-10, requirements.txt:1-7
Development Environment Architecture
The local setup consists of the FastAPI application (the "web" service) which acts as a bridge between client requests and the Odoo ERP system. The server architecture relies on environment variables for configuration, enabling seamless switching between local host services and containerized Odoo instances.
The diagram shows the request flow from a client through the FastAPI layer, which uses odoorpc to communicate with the Odoo backend and its associated database.
Sources: app/main.py:12-40, odoo/docker-compose.yml:3-60, docker-compose.yml:1-14
Execution Modes
1. Manual Uvicorn Execution
Developers can run the server directly on their host machine. This requires a Python 3.8+ environment and the installation of dependencies listed in requirements.txt. The server is launched using Uvicorn with the --reload flag enabled to support hot-reloading during development.
- Command:
uvicorn app.main:app --reload - Port: 8000 (Default)
Sources: README.md:12-34, requirements.txt:1-7
2. Docker Compose Environment
For a more isolated environment, Docker Compose builds the application container and injects environment variables defined in a .env file. The service is configured to automatically restart and reload code changes.
This sequence illustrates the container orchestration process where the web service is initialized and attempts to authenticate with the Odoo service.
Sources: docker-compose.yml:1-14, README.md:36-41, odoo/test_odoo_connection.py:6-14
Configuration and Environment Variables
The server relies on specific environment variables to establish a connection with the Odoo instance. These can be defined in a .env file or passed directly to the container environment.
| Variable | Description | Default Value |
|---|---|---|
ODOO_URL | The URL or hostname of the Odoo server | localhost |
ODOO_DB | Name of the Odoo database | mydb |
ODOO_USERNAME | Username for Odoo authentication | admin |
ODOO_PASSWORD | Password for Odoo authentication | admin |
Sources: app/main.py:12-15, docker-compose.yml:9-14, README.md:47-49
Core Components and Endpoints
FastAPI Application (app/main.py)
The main entry point initializes the FastAPI instance and defines the available routes. It uses the odoorpc library to handle the complexities of the Odoo RPC protocol.
- Root Endpoint (
GET /): Returns a simple welcome message. - Partners Endpoint (
GET /get/partners): Performs a login to Odoo, searches for records in theres.partnermodel, and returns names and emails.
Connectivity Testing
A utility script odoo/test_odoo_connection.py is provided to verify the local server's ability to reach the Odoo instance independently of the FastAPI web layer.
def test_odoo_connection():
odoo = odoorpc.ODOO('localhost', port=8069)
try:
odoo.login('odoodb', 'admin', 'admin')
print("Successfully connected to Odoo 17!")
except ConnectionError as e:
print(f"Error connecting to Odoo 17: {e}")
Sources: app/main.py:18-40, odoo/test_odoo_connection.py:6-14
Database and Backend Support
When running the full local stack via the Odoo-specific docker-compose (located in the odoo/ directory), the environment provides:
- Odoo 17 Service: Accessible on port
8069. - PostgreSQL 13 Database: Serves as the backend for Odoo with health checks to ensure availability.
Sources: odoo/docker-compose.yml:25-60
Summary
The local development server environment is a dual-mode setup providing a FastAPI-based REST gateway to Odoo. It leverages standard Python development tools (Uvicorn, FastAPI, odoorpc) and containerization (Docker Compose) to ensure a consistent environment for developing and testing Odoo integrations.
Sources: README.md:3-8, app/main.py:1-15