| import os, httpx | |
| from functools import lru_cache | |
| _KEY = os.getenv("MYGENE_KEY") | |
| _URL = "https://mygene.info/v3/query" | |
| async def fetch_gene_info(sym: str) -> dict: | |
| if not sym: | |
| return {} | |
| params = { | |
| "q" : sym, | |
| "fields": "symbol,name,summary,alias,entrezgene,location", | |
| "size" : 1, | |
| } | |
| if _KEY: | |
| params["api_key"] = _KEY | |
| async with httpx.AsyncClient(timeout=8) as c: | |
| r = await c.get(_URL, params=params) | |
| r.raise_for_status() | |
| return r.json().get("hits", [{}])[0] | |