FastAPI-based backend for OpenPecha.
openpecha-backend/
├── main.py # FastAPI entry point
├── routers/ # API route handlers
├── database/ # Database layer
├── models.py # Pydantic models
├── tests/ # Test suite
├── requirements.txt # Production dependencies
├── requirements_dev.txt # Development dependencies
└── gunicorn.conf.py # Production server config
-
Clone the repo
-
Create a virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate- Install dependencies
pip install -r requirements.txt
pip install -r requirements_dev.txt # For development- Copy environment template and configure
cp .env.example .env
# Edit .env with your Neo4j and AWS credentialsFrom the repository root:
source .venv/bin/activate
uvicorn main:app --reloadOr without activating the virtual environment:
./.venv/bin/uvicorn main:app --reloadThe API will be available at http://localhost:8000
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
- Health check: http://localhost:8000/__/health
The app initializes Neo4j and S3 when NEO4J_URI is set in .env. To run only
docs/health locally without database startup, temporarily unset NEO4J_URI:
unset NEO4J_URI
./.venv/bin/uvicorn main:app --reloadgunicorn main:app -c gunicorn.conf.pyTests spin up a disposable Neo4j container automatically via testcontainers. No manual Neo4j installation or env vars are needed.
-
Install dev dependencies:
pip install -r requirements_dev.txt
-
You need a running Docker-compatible runtime (Docker Desktop, Colima, Podman, etc.)
- Docker Desktop works out of the box
- Other runtimes — set
DOCKER_HOST:export DOCKER_HOST=unix://$HOME/.colima/default/docker.sock
pytest tests/Or with verbose output:
python -m pytest tests/ -vThe first run will pull the neo4j:2026.07.1 image (~500 MB), which is cached for
subsequent runs.
Deployment is handled automatically via GitHub Actions when pushing to main.
ssh ubuntu@<EC2_HOST>
cd /opt/openpecha-backend
git pull origin main
source .venv/bin/activate
pip install -r requirements.txt
sudo systemctl restart openpecha-api- Neo4j: Configured via
NEO4J_URI,NEO4J_USER,NEO4J_PASSWORDin.env - AWS S3: Configured via
AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY,AWS_S3_BUCKETin.env - OpenSearch content search: Configured via
OPENSEARCH_ENDPOINT - OpenSearch catalog search (person/text name and title search): Configured via
OPENSEARCH_ENDPOINTandOPENSEARCH_CATALOG_INDEX. Requires theanalysis-tibetanandanalysis-bdrcOpenSearch plugins on the cluster; for local tests setOPENSEARCH_TIBETAN_PLUGIN_ZIPandOPENSEARCH_BDRC_PLUGIN_ZIP. Seedocs/api-documentation/catalog-search-api.md.
API documentation available at: https://pecha-backend.web.app/docs