MyGene.Info Python Client

3.2.2 · active · verified Sat Apr 11

mygene is an easy-to-use Python wrapper to access MyGene.Info services, which provide simple-to-use REST web services to query/retrieve gene annotation data. It is currently at version 3.2.2 and is actively maintained, with releases tied to updates in the underlying MyGene.info API and its `biothings_client` dependency.

Warnings

Install

Imports

Quickstart

Initialize the MyGeneInfo client and perform basic queries for gene annotation data, demonstrating retrieval of single gene information and searching by symbol with field filtering.

import mygene

mg = mygene.MyGeneInfo()

# Get information for a single gene (Entrez ID for CDK2)
gene_info = mg.getgene(1017)
print(f"Gene Symbol: {gene_info.get('symbol')}, Name: {gene_info.get('name')}")

# Query for genes by symbol, returning only specific fields
query_results = mg.query('CDK2', fields='symbol,name,taxid', species='human', size=2)
for hit in query_results.get('hits', []):
    print(f"Query Hit: {hit.get('symbol')} ({hit.get('taxid')}) - {hit.get('name')}")

view raw JSON →