File size: 572 Bytes
686ea1e
8e8bfa6
b69651d
686ea1e
 
b69651d
3ef2946
686ea1e
 
 
 
 
 
 
 
6523621
 
686ea1e
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import os, httpx
from functools import lru_cache

_KEY  = os.getenv("MYGENE_KEY")
_URL  = "https://mygene.info/v3/query"

@lru_cache(maxsize=512)
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]