GeneWeb Python proxy server with backend toggle (OCaml/Python).
This is the core infrastructure for the migration strategy (MIG-INF-001, Issue #225). It provides a Python Flask server that can toggle between OCaml and Python backend implementations.
Micro-benchmarks comparing OCaml gwd vs Python backend are available. See docs/BENCHMARKS.md or run:
python -m python_app.benchmarks.benchmark_runnerCreate and activate a virtual environment (recommended):
# Create virtual environment
python3 -m venv venv
# Activate it
# On macOS/Linux:
source venv/bin/activate
# On Windows:
# venv\Scripts\activate
# Install dependencies
pip install -r requirements.txtVerify installation:
# Check Flask is installed
python -c "import flask; print(f'Flask {flask.__version__} installed')"# Make sure venv is activated (you should see (venv) in your prompt)
source venv/bin/activate # On macOS/Linux
# OCaml backend (default) - proxies to OCaml gwd
BACKEND=ocaml python -m python_app.app
# Python backend - uses migrated functions
BACKEND=python python -m python_app.app
# With custom port
FLASK_PORT=2318 python -m python_app.appNote: Make sure OCaml gwd is running if using BACKEND=ocaml (or the proxy will fail).
- Server URL: http://localhost:2318/test (default)
- Health Check: http://localhost:2318/health
- Debug Config: http://localhost:2318/debug/config (if DEBUG=true)
Set via environment variables:
BACKEND:ocamlorpython(default:ocaml)FLASK_HOST: Flask host (default:127.0.0.1)FLASK_PORT: Flask port (default:2318)GENEWEB_DIR: Path to GeneWeb directory (default:GeneWeb)GENEWEB_BASE: Base name (default:test)GENEWEB_LANG: Default language (default:en)OCAML_GWD_PORT: OCaml gwd port (default:2317)FLASK_DEBUG: Enable debug mode (default:false)
┌─────────────┐
│ Browser │
└──────┬──────┘
│ HTTP
▼
┌─────────────────────┐
│ Python Flask App │
│ (python_app/app) │
└──────┬───────────────┘
│
├─ BACKEND=python ──► tests/python/utils/ (migrated functions)
│
└─ BACKEND=ocaml ────► ocaml_bridge ──► OCaml gwd (subprocess)
app.py: Main Flask applicationconfig.py: Configuration and backend togglemigrated/: Imports fromtests/python/utils/(migrated functions)- Issue: MIG-INF-002 (#226)
- Exposes all migrated utility functions (name, string, HTTP, HTML, number, roman, date utilities)
- Used when
BACKEND=pythonto access Python implementations - Validated by
tests/python/unit/test_migrated_module.py(24 tests)
routes/: HTTP route handlersperson.py: Person detail pagesfamily.py: Family relationship pagessearch.py: Search functionalitystats.py: Statistics pages
ocaml_bridge.py: Subprocess calls to OCaml binaries
- Proxies all requests to OCaml
gwdserver - Uses subprocess calls via
ocaml_bridge - OCaml
gwdmust be running onOCAML_GWD_PORT(default: 2317)
- Uses migrated functions from
tests/python/utils/ - Processes requests with Python implementations
- Still uses OCaml for:
- Database access (not yet migrated)
- GEDCOM export/import (complex operations)
- Complex algorithms (search, relationships)
✅ Implemented:
- Flask application structure
- Backend toggle mechanism
- Route handlers (person, family, search, stats)
- OCaml bridge (subprocess calls)
- Migrated function imports
⏳ In Progress:
- Full Python implementation of routes (currently proxies to OCaml)
- Database access layer (still using OCaml)
- Template rendering (still using OCaml HTML)
🔮 Future Work:
- Full Python implementation
- Template rendering in Python
- Database access in Python
- Dual-run validation (OCaml vs Python)
Prerequisites: Make sure OCaml gwd is running if using BACKEND=ocaml or if routes need to proxy.
# Activate venv (if not already active)
source venv/bin/activate
# Start OCaml gwd (if using BACKEND=ocaml or proxy routes)
cd GeneWeb
./gw/gwd -hd ./gw -bd ./bases -p 2317 -lang en &
cd ..
# Test health endpoint
curl http://localhost:2318/health
# Test home page
curl http://localhost:2318/test
# Test person page
curl "http://localhost:2318/test?p=Charles&n=Windsor"
# Test with Python backend
BACKEND=python python -m python_app.app
curl http://localhost:2318/health- Issue: #225 (MIG-INF-001)
- Migration Status:
docs/MIGRATION_STATUS.md - ADR-006: Utility Function Migration Approach
- ADR-007: CI Quality Gates Strategy