Download mcp/drugcentral_ext.py from mgbam/MCP_Res: direct link, hf CLI and curl.
- Browser
- Download file 950 Bytes
-
https://huggingface.co/spaces/mgbam/MCP_Res/resolve/1f7d1c0d89b17a6183262c4cefdae7ac182f97fd/mcp/drugcentral_ext.py
- Command line
-
hf download hf://spaces/mgbam/MCP_Res@1f7d1c0d89b17a6183262c4cefdae7ac182f97fd/mcp/drugcentral_ext.py
-
curl -L -o drugcentral_ext.py https://huggingface.co/spaces/mgbam/MCP_Res/resolve/1f7d1c0d89b17a6183262c4cefdae7ac182f97fd/mcp/drugcentral_ext.py
950 Bytes
| """ | |
| DrugCentral SMART API helper | |
| Docs: https://drugcentral.org/api (public; key optional) | |
| • Returns {} on any error so orchestrator never fails. | |
| • Optional DRUGCENTRAL_KEY (JWT) lifts the rate-limit. | |
| """ | |
| from __future__ import annotations | |
| import os, httpx, asyncio | |
| from functools import lru_cache | |
| from typing import Dict | |
| _TOKEN = os.getenv("DRUGCENTRAL_KEY") # optional | |
| _BASE = "https://drugcentral.org/api/v1/drug" | |
| _HDR = {"Accept": "application/json"} | |
| if _TOKEN: | |
| _HDR["Authorization"] = f"Bearer {_TOKEN}" | |
| async def fetch_drugcentral(name: str) -> Dict: | |
| """Return DrugCentral record or {}.""" | |
| try: | |
| async with httpx.AsyncClient(timeout=10, headers=_HDR) as cli: | |
| r = await cli.get(_BASE, params={"name": name}) | |
| if r.status_code == 404: | |
| return {} | |
| r.raise_for_status() | |
| return r.json() | |
| except Exception: | |
| return {} | |