Ebovir/pubmed
0
PubMed Proxy Service (Port 8080) ================================
A FastAPI microservice for searching PubMed and managing a local knowledge base of medical literature. Part of the AI-Doctor platform.
What you get ------------
/health: Health check (no auth required)/pubmed/search: keywords + filters → PMIDs (deduped, sorted)/pubmed/fetch: PMIDs or query → unified paper JSON (title/abstract/doi/…)/kb/ingest: upsert papers into local JSON folder or MongoDB/kb/papers/{pmid}: get one paper from local store/kb/search: simple keyword search (title/abstract) with year filters/kb/fetch_or_fill: fetch from KB, auto-fill missing from NCBI/kb/semantic_search: reserved, returns "not enabled"
Authentication
--------------
All endpoints except /health require X-API-Key header.
Architecture ------------
- Tech stack: Python + FastAPI + httpx
- Storage: local JSON files (or MongoDB when configured)
- Semantic search: disabled but endpoint is reserved
- Throughput target: default 200 per query, chunk efetch at 100 PMIDs
- CORS enabled for frontend origins
Run locally -----------
cd pubmed_proxy_service
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txt
cp .env.example .env # Configure as needed
uvicorn app.main:app --reload --port 5007
Deploy to Vercel ---------------- See DEPLOY.md for full Vercel deployment instructions.
Quick deploy:
npm i -g vercel
cd pubmed_proxy_service
vercel
Requires:
- MongoDB Atlas (free tier works)
- Environment variables set in Vercel dashboard
Key configs (app/config.py) ---------------------------
DEFAULT_MAX_RESULTS=200EFETCH_CHUNK_SIZE=100NCBI_MAX_RETRIES=5, backoff with jitterSEARCH_CACHE_TTL=6*3600,FETCH_CACHE_TTL=7*24*3600- Data dir:
data/papers/(auto-created)
API examples ------------
- Health check (no auth):
curl http://localhost:5007/health
- Search:
curl -X POST http://localhost:5007/pubmed/search \
-H "Content-Type: application/json" \
-H "X-API-Key: dev-key-change-in-production" \
-d '{"keywords":["ADHD","dopamine deficiency"],"filters":{"year_from":2018,"year_to":2024},"max_results":50}'
- Fetch by PMIDs:
curl -X POST http://localhost:5007/pubmed/fetch \
-H "Content-Type: application/json" \
-H "X-API-Key: dev-key-change-in-production" \
-d '{"pmids":["12345678","98765432"]}'
- KB ingest:
curl -X POST http://localhost:5007/kb/ingest \
-H "Content-Type: application/json" \
-H "X-API-Key: dev-key-change-in-production" \
-d '{"papers":[{"pmid":"123","title":"t","abstract":"a","pubmed_url":"https://pubmed.ncbi.nlm.nih.gov/123/"}]}'
Notes -----
- E-utilities base:
https://eutils.ncbi.nlm.nih.gov/entrez/eutils/ - Uses
esearch(withusehistory=y) then chunkedefetch(rettype=abstract, retmode=xml). - Not touching existing
DataScraping-mainscripts; all new code lives here.
