skillfed

pyfaidx

pyfaidx: efficient pythonic random access to fasta subsequences

pyfaidx v0.9.0.4 529.9K downloads/30d#6,159 on PyPI489
Permissive license BSD-3-Clause Active released

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 pyfaidx

uv

uv add pyfaidx

poetry

poetry add pyfaidx

Installing 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

Development Status :: 5 - Production/StableEnvironment :: ConsoleIntended Audience :: Science/ResearchLicense :: OSI Approved :: BSD LicenseNatural Language :: EnglishOperating System :: UnixProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: PyPyTopic :: Scientific/Engineering :: Bio-Informatics

Tags

fasta file random accessfaidx index pythonsequence retrieval fastadna sequence slicingfasta subsequence extractionsamtools faidx pythongenomic sequence indexing
bioinformaticsgenomicsfasta-indexing

More Bio-Informatics packages