BioThings Client

0.5.0 · active · verified Fri Apr 10

biothings_client is an easy-to-use Python wrapper to access any BioThings API-based backend service. It provides unified access to various biological data APIs such as MyGene.Info, MyVariant.Info, MyChem.Info, MyDisease.Info, MyGeneset.Info, and MyTaxon.Info. The library is actively maintained, with the current stable version being 0.5.0, and typically sees updates and bug fixes on a regular cadence.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to instantiate clients for MyGene.info and MyVariant.info, fetch a single gene by ID, query multiple genes by symbol, and fetch a variant annotation. It uses common fields for demonstration.

from biothings_client import get_client

# Get a client for the MyGene.info API
mg_client = get_client("gene")

# Fetch gene annotation for a specific Entrez gene ID
gene_id = "1017" # Example: CDK2 gene
result = mg_client.getgene(gene_id, fields="symbol,name,entrezgene")
print(f"Gene ID {gene_id}: {result.get('symbol')} - {result.get('name')}")

# Query multiple genes by symbol
gene_symbols = ["CDK2", "BRCA1", "TP53"]
results = mg_client.querymany(gene_symbols, scopes="symbol", fields="name,entrezgene,ensembl.gene")
for res in results:
    print(f"Symbol: {res.get('query')}, Name: {res.get('name')}, Entrez: {res.get('entrezgene')}")

# Get a client for the MyVariant.info API
mv_client = get_client("variant")

# Fetch variant annotation
variant_id = "chr1:g.140453134T>C"
variant_result = mv_client.getvariant(variant_id)
# print(f"Variant {variant_id}: {variant_result}") # Uncomment to see full result
print(f"Variant {variant_id}: {variant_result.get('_id')} - {variant_result.get('dbsnp', {}).get('rsid')}")

view raw JSON →