pyfaidx
pyfaidx: efficient pythonic random access to fasta subsequences
What it is and what it does
pyfaidx is a pure Python implementation of samtools' faidx functionality, enabling efficient random access to any subsequence in a FASTA file without loading the entire file into memory. It creates a small flat index file (.fai) that allows seeking directly to the sequence you need. The package provides both a Python API (with dictionary-like and method-based access) and a command-line tool for FASTA manipulation without programming.
The library supports slicing, reverse complements, spliced sequences, and coordinate transformations (1-based and 0-based). It works with sequences indexed by name or position, handles custom key functions for flexible naming schemes, and can filter sequences during indexing. The API is compatible with pygr's seqdb module, making it a drop-in replacement for existing bioinformatics workflows.
Use it for:
- Extract specific genomic regions from reference genomes for variant analysis or annotation pipelines.
- Build sequence databases for rapid lookup of genes or transcripts by identifier without full file loads.
- Perform reverse-complement operations on DNA sequences for primer design or alignment validation.
- Slice and manipulate FASTA sequences programmatically in Python-based bioinformatics workflows.
- Use the faidx command-line tool to extract or modify FASTA records without writing custom scripts.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides fast random access to subsequences in FASTA files using a samtools-compatible index, with a pure Python implementation for indexing, retrieval, and in-place modification.
Yes. pyfaidx is production-stable, actively maintained, has no known vulnerabilities, and solves a real problem in bioinformatics workflows. Low install friction and permissive licensing make it a straightforward choice for anyone working with FASTA files in Python.
Install
pyfaidx on PyPI
pip
pip install pyfaidxuv
uv add pyfaidxpoetry
poetry add pyfaidxInstalling pyfaidx
Before you install
Low friction: pure Python with only two lightweight runtime dependencies (importlib_metadata and packaging). Active maintenance with a recent release 148 days ago and 489 repository stars.
License in practice
BSD-3-Clause is permissive; you can use this package freely in commercial and proprietary projects with minimal restrictions.
Quickstart
pip install pyfaidx
from pyfaidx import Fasta
genes = Fasta('genes.fasta')
seq = genes['sequence_id'][200:230]
print(seq.seq)
Verify before relying
- Whether the command-line faidx script is reliably available after installation on all supported platforms.
- Performance characteristics when working with very large FASTA files or many concurrent accesses.
Package facts
| License | BSD-3-Clause (permissive) |
| Python support | supports the current Python release (>=3.7) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — importlib_metadata, packaging |
| Maintenance | actively maintained — 148 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 529,907/month — #6,159 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pyfaidx-0.9.0.4-py3-none-any.whl
Tags
More Bio-Informatics packages
NetworkX provides data structures and…
permissive · top 1,000 on PyPI
biopythonBiopython provides Python tools for…
unclear · top 5,000 on PyPI
firecrawl-pyClient library for the Firecrawl API that…
permissive · top 5,000 on PyPI
intervaltreeA self-balancing interval tree data structure…
permissive · top 5,000 on PyPI
albumentationsAlbumentations applies image transformations to…
permissive · top 5,000 on PyPI
PubChemPyPubChemPy is a Python wrapper around the…
permissive · top 5,000 on PyPI
pysampysam reads, manipulates, and writes genomic…
permissive · top 5,000 on PyPI
pyensemblPyEnsembl provides a Python interface to query…
permissive · top 15,000 on PyPI
dnaiodnaio reads and writes FASTQ, FASTA, and uBAM…
permissive · top 15,000 on PyPI
biocommons.seqrepoSeqRepo stores and retrieves biological…
permissive · top 15,000 on PyPI
cyvcf2cyvcf2 is a Cython wrapper around htslib that…
permissive · top 15,000 on PyPI
fuzzysearchFinds approximate substring matches in text or…
permissive · top 15,000 on PyPI
pyrangesPyRanges provides efficient querying and…
permissive · top 15,000 on PyPI
pyteomicsPyteomics provides Python tools for proteomics…
permissive · top 15,000 on PyPI
bx-pythonbx-python provides Python classes and utilities…
permissive · top 15,000 on PyPI
RUSTRUST normalizes ribosome profiling (Ribo-seq)…
permissive · top 15,000 on PyPI