{"id":3003,"library":"mygene","title":"MyGene.Info Python Client","description":"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.","status":"active","version":"3.2.2","language":"en","source_language":"en","source_url":"https://github.com/biothings/mygene.py","tags":["bioinformatics","genomics","data access","biothings","genes"],"install":[{"cmd":"pip install mygene","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core dependency; mygene is a thin wrapper over biothings_client since v3.1.0.","package":"biothings_client","optional":false},{"reason":"Required for returning results as pandas DataFrames.","package":"pandas","optional":true}],"imports":[{"note":"While 'mygene' internally uses 'biothings_client', the primary public interface for 'mygene' users remains 'mygene.MyGeneInfo()' for consistency and direct library usage.","wrong":"from biothings_client import get_client; mg = get_client('gene')","symbol":"MyGeneInfo","correct":"from mygene import MyGeneInfo"}],"quickstart":{"code":"import mygene\n\nmg = mygene.MyGeneInfo()\n\n# Get information for a single gene (Entrez ID for CDK2)\ngene_info = mg.getgene(1017)\nprint(f\"Gene Symbol: {gene_info.get('symbol')}, Name: {gene_info.get('name')}\")\n\n# Query for genes by symbol, returning only specific fields\nquery_results = mg.query('CDK2', fields='symbol,name,taxid', species='human', size=2)\nfor hit in query_results.get('hits', []):\n    print(f\"Query Hit: {hit.get('symbol')} ({hit.get('taxid')}) - {hit.get('name')}\")","lang":"python","description":"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."},"warnings":[{"fix":"Review the MyGene.info v3 API migration guide if your application relies on specific data structures or 'dotfield' behavior for annotation fields. Update your code to handle the new JSON structure or explicitly request 'dotfield=1' if needed.","message":"The `mygene` package became a thin wrapper around `biothings_client` since v3.1.0. While the `mygene.MyGeneInfo()` interface is maintained, the underlying MyGene.info v3 API introduced changes to data structures for fields like `refseq`, `accession`, `ensembl`, and `exons`. Also, the default behavior for 'dotfield' notation changed, requiring explicit `dotfield=1` for the old behavior.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Replace calls to `mg.findgenes(...)` with `mg.querymany(...)`. The arguments are generally compatible.","message":"The `findgenes()` method was deprecated in version 2.0.0. It is kept as an alias for `querymany()` for backward compatibility, but `querymany()` should be used instead for new code.","severity":"deprecated","affected_versions":">=2.0.0"},{"fix":"Strip the version postfix (e.g., '.14') from Ensembl gene IDs before passing them to `mg.getgene()`.","message":"When querying with Ensembl gene IDs that include a version postfix (e.g., 'ENSG00000000003.14'), the `getgene()` method might not return results. The postfix should be removed.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always use the `fields` parameter instead of `filter` when calling `query()` or `querymany()` to specify desired return fields.","message":"In MyGene.info API v2 (and by extension older `mygene` client versions), the 'filter' parameter was used for specifying returned fields. This parameter was replaced by 'fields' in MyGene.info API v2, though 'filter' was kept for back-compatibility in the client. Users should use 'fields' for clarity and future compatibility.","severity":"gotcha","affected_versions":"<3.0.0 (and if using older API endpoints)"},{"fix":"Ensure you are using the default API endpoint unless you have a specific reason to access an older, unmaintained version. Do not rely on data from `mg.url='http://mygene.info/v2'` for up-to-date information.","message":"While the `mygene` client defaults to the latest MyGene.info API (v3), older API versions (e.g., v2) can still be accessed by explicitly setting `mg.url`. However, data from older API versions are no longer updated.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}