Create drugcentral.py
Browse files- mcp/drugcentral.py +17 -0
mcp/drugcentral.py
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""DrugCentral async wrapper (https://drugcentral.org/api).
|
2 |
+
Provides drug metadata, approvals, MoA, off‑label, etc.
|
3 |
+
"""
|
4 |
+
|
5 |
+
import httpx, asyncio
|
6 |
+
from functools import lru_cache
|
7 |
+
|
8 |
+
_BASE = "https://drugcentral.org/api/v1/drug"
|
9 |
+
|
10 |
+
@lru_cache(maxsize=256)
|
11 |
+
async def fetch_drugcentral(drug_name: str) -> dict | None:
|
12 |
+
async with httpx.AsyncClient(timeout=10) as client:
|
13 |
+
resp = await client.get(_BASE, params={"name": drug_name})
|
14 |
+
if resp.status_code == 404:
|
15 |
+
return None
|
16 |
+
resp.raise_for_status()
|
17 |
+
return resp.json()
|