import httpx, asyncio, datetime | |
_BASE = "https://clinicaltrials.gov/api/v2/studies" | |
async def search_trials(query: str, max_n: int = 20) -> list[dict]: | |
async with httpx.AsyncClient(timeout=15) as cli: | |
r = await cli.get(_BASE, params={ | |
"query": query, | |
"pageSize": max_n, | |
"fields": "nctId,briefTitle,phase,status,startDate" | |
}) | |
r.raise_for_status() | |
return r.json().get("studies", []) | |