| import os |
| import platform |
| from fastapi import FastAPI |
| from fastapi.responses import HTMLResponse |
|
|
| app = FastAPI( |
| title="Odoo Space API", |
| description="This is a lightweight API serving for Odoo deployment on Hugging Face Spaces.", |
| version="19.0" |
| ) |
|
|
| @app.get("/health") |
| def health(): |
| """ |
| Mandatory endpoint returning HTTP 200 when the app is ready. |
| """ |
| return {"status": "pass"} |
|
|
| @app.get("/api-docs", response_class=HTMLResponse) |
| def api_docs(): |
| """ |
| Mandatory endpoint that documents all available API endpoints. |
| """ |
| html_content = """ |
| <!DOCTYPE html> |
| <html> |
| <head> |
| <title>Odoo Space API Documentation</title> |
| <style> |
| body { |
| font-family: Arial, sans-serif; |
| margin: 40px; |
| background-color: #f4f6f9; |
| color: #333; |
| } |
| h1 { |
| color: #7C5BBA; |
| } |
| .endpoint { |
| background: white; |
| padding: 20px; |
| margin-bottom: 20px; |
| border-radius: 8px; |
| box-shadow: 0 2px 4px rgba(0,0,0,0.1); |
| } |
| .method { |
| font-weight: bold; |
| padding: 4px 8px; |
| border-radius: 4px; |
| color: white; |
| display: inline-block; |
| margin-right: 10px; |
| } |
| .get { background-color: #61afff; } |
| .post { background-color: #49cc90; } |
| .path { |
| font-family: monospace; |
| font-size: 1.1em; |
| font-weight: bold; |
| } |
| pre { |
| background: #f8f8f8; |
| padding: 10px; |
| border: 1px solid #ddd; |
| border-radius: 4px; |
| overflow-x: auto; |
| } |
| </style> |
| </head> |
| <body> |
| <h1>Odoo Space API Documentation</h1> |
| <p>Welcome to the Odoo deployment Space. This lightweight API ensures the health and deployment status of the Odoo application environment.</p> |
| |
| <h2>Mandatory Endpoints</h2> |
| |
| <div class="endpoint"> |
| <span class="method get">GET</span><span class="path">/health</span> |
| <p><strong>Purpose:</strong> Returns HTTP 200 when the app is ready. Required for Hugging Face to transition the Space from <em>starting</em> to <em>running</em>.</p> |
| <p><strong>Response Example:</strong></p> |
| <pre>{"status": "pass"}</pre> |
| </div> |
| |
| <div class="endpoint"> |
| <span class="method get">GET</span><span class="path">/api-docs</span> |
| <p><strong>Purpose:</strong> Documents all available API endpoints. Exposes this interactive documentation.</p> |
| </div> |
| |
| <h2>Functional Endpoints</h2> |
| |
| <div class="endpoint"> |
| <span class="method get">GET</span><span class="path">/api/version</span> |
| <p><strong>Purpose:</strong> Returns the application and Odoo version details.</p> |
| <p><strong>Response Example:</strong></p> |
| <pre>{"version": "19.0", "sdk": "docker"}</pre> |
| </div> |
| |
| <div class="endpoint"> |
| <span class="method get">GET</span><span class="path">/api/modules</span> |
| <p><strong>Purpose:</strong> Lists simulated or available Odoo modules.</p> |
| <p><strong>Response Example:</strong></p> |
| <pre>["base", "web", "crm", "website", "ecommerce", "inventory", "project"]</pre> |
| </div> |
| |
| <div class="endpoint"> |
| <span class="method get">GET</span><span class="path">/api/sysinfo</span> |
| <p><strong>Purpose:</strong> Returns OS, platform, and python execution environment info.</p> |
| <p><strong>Response Example:</strong></p> |
| <pre>{"os": "Linux", "python_version": "3.12.x", "arch": "x86_64"}</pre> |
| </div> |
| |
| <div class="endpoint"> |
| <span class="method get">GET</span><span class="path">/api/ping</span> |
| <p><strong>Purpose:</strong> Simple ping-pong endpoint to verify responsiveness.</p> |
| <p><strong>Response Example:</strong></p> |
| <pre>{"ping": "pong"}</pre> |
| </div> |
| </body> |
| </html> |
| """ |
| return HTMLResponse(content=html_content, status_code=200) |
|
|
| @app.get("/api/version") |
| def version(): |
| """ |
| Returns application and Odoo version details. |
| """ |
| return {"version": "19.0", "sdk": "docker"} |
|
|
| @app.get("/api/modules") |
| def modules(): |
| """ |
| Lists Odoo modules in this repository. |
| """ |
| return ["base", "web", "crm", "website", "ecommerce", "inventory", "project"] |
|
|
| @app.get("/api/sysinfo") |
| def sysinfo(): |
| """ |
| Returns platform environment details. |
| """ |
| return { |
| "system": platform.system(), |
| "release": platform.release(), |
| "version": platform.version(), |
| "machine": platform.machine(), |
| "python_version": platform.python_version() |
| } |
|
|
| @app.get("/api/ping") |
| def ping(): |
| """ |
| Simple ping-pong endpoint to verify responsiveness. |
| """ |
| return {"ping": "pong"} |
|
|