ens-tables

Ensembl gene annotation, cross-references and homologs as pandas DataFrames, read from Ensembl’s bulk files and cached locally.

  • Annotation by release: genes, transcripts, cross-references and orthologs of Ensembl releases up to 116, queried with BioMart’s attribute and filter names.

  • New Ensembl platform: genes, transcripts, cross-references and homologies published after release 116, with BioMart’s column names where the meaning is the same.

  • Existing BioMart code: common pybiomart and scanpy.queries calls run after an import change.

  • Reproducible and offline: releases are pinned, downloads are checked against Ensembl’s checksums, and cached tables need no network.

Ensembl BioMart and the REST API stay at release 116, and later annotation is published on the new Ensembl platform. For releases up to 116, ens-tables reads the tables that Ensembl publishes behind BioMart; for later annotation, it reads the new platform’s files.

pip install ens-tables

BioMart queries

import ens_tables as et

et.query(
    "hsapiens_gene_ensembl",
    ["ensembl_gene_id", "hgnc_symbol", "chromosome_name", "start_position", "end_position"],
    {"chromosome_name": "MT"},
    release=116,
)

et.datasets()  # datasets and assemblies of a release
et.attributes("hsapiens_gene_ensembl")  # attribute names, pages and availability
et.filters("hsapiens_gene_ensembl")

Attribute and filter names are BioMart’s. Queries cover the Ensembl Genes mart of Ensembl releases, not the variation or regulation marts or Ensembl Genomes divisions such as Ensembl Plants. Duplicate rows are dropped, as in BioMart; pass unique=False to keep them. Sequences and other server-computed attributes are not available, nor is the chromosomal_region filter. See the examples for common tasks and help(et.query) for filter values.

New Ensembl platform

human = {"assembly": "GCA_000001405.29", "annotation": "2026_04"}

genes = et.genes(**human)
transcripts = et.transcripts(**human)
entrez = et.xrefs(**human, db="NCBI gene (formerly Entrezgene)")
mouse = et.homologies(**human, homology="2026_07_13", ref_species="mus_musculus")

et.annotations("GCA_000001405.29")  # published providers and dates, read online

Genome

assembly

annotation

homology

Human GRCh38.p14

GCA_000001405.29

2026_04

2026_07_13

Mouse GRCm39

GCA_000001635.9

2026_04

2026_07_13

The assembly accession and annotation date select the tables, as release does for BioMart queries, and annotations() lists the published dates. See new platform tables for the columns and for tasks such as tx2gene.

Code written for pybiomart and scanpy.queries

from ens_tables.pybiomart import Dataset

dataset = Dataset(name="hsapiens_gene_ensembl", host="http://www.ensembl.org")
dataset.query(attributes=["ensembl_gene_id", "external_gene_name"], filters={"chromosome_name": ["MT"]})

from ens_tables import scanpy as queries

queries.mitochondrial_genes("hsapiens")

The host selects the release, and www.ensembl.org means 116. The migration guide lists the supported calls and hosts.

Cache and offline use

Files are downloaded on first use and cached as parquet in ~/.cache/ens-tables; set ENS_TABLES_CACHE to move the cache. Run the intended calls once online before working offline. In our human benchmarks, first calls needed 7 to 162 MiB of downloads and up to half a minute of local processing; cached calls took 0.03 to 2.1 seconds. To see downloads and conversions as they run, turn on logging: logging.basicConfig(level=logging.INFO).

Documentation

  • Examples: tasks from the biomaRt vignette, pybiomart and Scanpy, with their outputs.

  • New platform tables: columns, versions and common tasks such as tx2gene.

  • Migration guide: pybiomart, scanpy.queries and martservice XML, the differences from a BioMart server, and offline use in CI.

  • Validation: comparisons with BioMart, pybiomart, Scanpy and release 116.

  • Performance: time, memory and download size per call.

Development

uv run --group test pytest                # offline tests on a small fixture
uv run --group test pytest -m internet    # downloads from the Ensembl FTP site
uvx ruff check . && uvx ruff format --check .

License

The source code is licensed under BSD-3-Clause. Upstream test data and configuration keep their own terms; see test data provenance.