Skip to content

Commit 8479a7f

Browse files
feat(medcat-service): Add root_path support using pydantic settings (#60)
1 parent a891f33 commit 8479a7f

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from pydantic import Field
2+
from pydantic_settings import BaseSettings
3+
4+
5+
class Settings(BaseSettings):
6+
app_root_path: str = Field(
7+
default="/", description="The Root Path for the FastAPI App", examples=["/medcat-service"]
8+
)

medcat-service/medcat_service/dependencies.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from fastapi import Depends
55

6+
from medcat_service.config import Settings
67
from medcat_service.nlp_processor.medcat_processor import MedCatProcessor
78

89

@@ -11,4 +12,9 @@ def get_medcat_processor() -> MedCatProcessor:
1112
return MedCatProcessor()
1213

1314

15+
@lru_cache
16+
def get_settings() -> Settings:
17+
return Settings()
18+
19+
1420
MedCatProcessorDep = Annotated[MedCatProcessor, Depends(get_medcat_processor)]

medcat-service/medcat_service/main.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
from fastapi import FastAPI, Request
33
from fastapi.responses import JSONResponse
44

5+
from medcat_service.dependencies import get_settings
56
from medcat_service.routers import admin, health, legacy, process
67
from medcat_service.types import HealthCheckFailedException
78

9+
settings = get_settings()
10+
811
app = FastAPI(
912
title="MedCAT Service",
1013
summary="MedCAT Service",
@@ -17,6 +20,7 @@
1720
"name": "Apache 2.0",
1821
"identifier": "Apache-2.0",
1922
},
23+
root_path=settings.app_root_path,
2024
)
2125

2226
app.include_router(admin.router)

medcat-service/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ medcat[meta-cat,spacy,deid]~=2.0.0b
77
transformers>=4.34.0,<5.0.0
88
requests==2.32.4
99
fastapi[standard]==0.113.0
10-
pydantic==2.9.2
10+
pydantic==2.9.2
11+
pydantic-settings==2.10.1

0 commit comments

Comments
 (0)