Written and maintained by CASRAI Editorial Board
Last updated
What is Biopython?
Biopython is an open-source suite of Python modules designed for computational molecular biology, bioinformatics analysis, and pipeline automation. Initiated in 1999 and documented by Cock et al. in Bioinformatics (2009), the toolkit provides standardized data representations for biological sequences, parsers for common laboratory file formats, programmatic interfaces to biological databases, and wrappers for external analytical tools. Within research environments, Biopython serves as a core software layer for processing sequence data and automating repetitive bioinformatics tasks.
As detailed in our guide explaining what bioinformatics is and how it structures research, computational biology relies heavily on standardized scripting languages. Biopython addresses the common operational challenge of wrangling heterogeneous genomic formats and interfacing with public data repositories like the National Center for Biotechnology Information (NCBI).
Who runs it and what it covers
Biopython is maintained by an international volunteer community of bioinformaticians and software engineers under the organizational umbrella of the Open Bioinformatics Foundation (OBF). The OBF is a non-profit organization that provides fiscal sponsorship, domain registration, continuous integration infrastructure, and community governance for open-source life-sciences software, including BioPerl, BioJava, and BioRuby. Biopython participates actively in community initiatives such as the Bioinformatics Open Source Conference (BOSC) and Google Summer of Code (GSoC).
Biopython is distributed under the Biopython License Agreement, a permissive open-source license closely based on the BSD 3-Clause license. This framework grants researchers, academic laboratories, and commercial organizations full freedom to inspect, adapt, and embed Biopython into internal pipelines and commercial software without license fees. In computational research, following the FAIR4RS principles for research software stewardship ensures that analytical code depending on Biopython remains reproducible and verifiable.
The library covers core functional areas in computational biology:
- Sequence representation: The
Bio.Seqmodule defines sequence objects supporting transcription, translation, and reverse complementation. - Annotated records: The
Bio.SeqRecordmodule combines sequence strings with identifiers, annotations, coordinate features (SeqFeature), and per-letter quality metrics. - File input/output: The
Bio.SeqIOandBio.AlignIOmodules provide iterative stream parsing and serialization for FASTA, FASTQ, GenBank, EMBL, and alignment formats. - Online database clients: The
Bio.Entrezmodule provides client access to NCBI Entrez E-utilities for literature and sequence retrieval. - Structural biology: The
Bio.PDBmodule implements the Structure-Model-Chain-Residue-Atom (SMCRA) hierarchy for PDB and mmCIF file analysis. - Pairwise alignments: The
Bio.Alignmodule offers thePairwiseAlignerobject for global and local dynamic programming alignments. - Phylogenetics: The
Bio.Phylomodule parses and renders phylogenetic trees in Newick, NEXUS, and phyloXML formats.
How to install and use it
Researchers can integrate Biopython into local scripts, virtual environments, or High-Performance Computing (HPC) workflows using the following standard steps:
Step 1: Install Biopython and dependencies
Biopython requires Python 3 and depends on NumPy for numerical arrays and structural coordinate transformations. Python 2 support ended with version 1.77. Install via PyPI or Conda:
pip install biopython
# or via conda-forge:
conda install -c conda-forge biopython
Step 2: Manipulate sequences with Bio.Seq
Biopython’s Seq object provides biological sequence operations that enforce conventional 5′ to 3′ orientation and biological transformations:
from Bio.Seq import Seq
dna = Seq("ATGGCCATTGTAATGGGCCGCTGAAAGGGTGCCCGATAG")
mrna = dna.transcribe()
protein = dna.translate()
rev_comp = dna.reverse_complement()
To understand the rules governing strand orientation and ambiguous base complementation, see our reference on calculating the reverse complement of DNA.
Step 3: Parse sequence files with Bio.SeqIO
The Bio.SeqIO interface parses files iteratively without reading entire datasets into system memory at once:
from Bio import SeqIO
with open("sequences.fasta", "r") as handle:
for record in SeqIO.parse(handle, "fasta"):
print(f"ID: {record.id}, Length: {len(record.seq)}")
For FASTQ files, per-base PHRED quality scores are available directly within record.letter_annotations["phred_quality"].
Step 4: Query NCBI databases with Bio.Entrez
The Bio.Entrez module queries NCBI E-utilities. Per NCBI policy, users must supply an email address to identify their client:
from Bio import Entrez, SeqIO
Entrez.email = "[email protected]"
handle = Entrez.esearch(db="nucleotide", term="Cyp2d6[Gene] AND human[Organism]", retmax=3)
record_ids = Entrez.read(handle)["IdList"]
handle.close()
fetch_handle = Entrez.efetch(db="nucleotide", id=record_ids[0], rettype="gb", retmode="text")
record = SeqIO.read(fetch_handle, "genbank")
fetch_handle.close()
For large-scale repository deposition of raw sequencing reads, consult our guide to submitting sequence data to NCBI SRA.
Step 5: Perform pairwise alignment with Bio.Align
The modern Bio.Align.PairwiseAligner replaces legacy alignment wrappers with a dynamic programming engine:
from Bio import Align
aligner = Align.PairwiseAligner()
aligner.mode = "global" # Needleman-Wunsch
aligner.match_score = 1.0
aligner.mismatch_score = -2.0
score = aligner.score("GAACT", "GAT")
Step 6: Inspect macromolecular structures with Bio.PDB
The Bio.PDB parser organizes structural data into the SMCRA hierarchy (Structure, Model, Chain, Residue, Atom):
from Bio.PDB import PDBParser
parser = PDBParser(QUIET=True)
structure = parser.get_structure("protein", "sample.pdb")
for model in structure:
for chain in model:
for residue in chain:
if residue.has_id("CA"):
print(residue["CA"].coord)
When mapping structural coordinates back to genomic variant annotations, refer to our walkthrough on reading a VCF file.
Strengths and limits
Deploying Biopython effectively requires understanding its architectural advantages and constraints:
Strengths
- Broad format support: Reads and writes dozens of standard formats (FASTA, FASTQ, GenBank, EMBL, PDB, mmCIF, Newick), avoiding custom text-parsing scripts.
- Unified data model: The
SeqRecordobject creates a common interface across different data formats and connects smoothly with NumPy and Pandas. - NCBI Entrez access: Handles query construction, rate-limit management, and XML parsing for literature and sequence records.
- Permissive licensing: The BSD-style license allows deployment in academic and commercial software without license fees.
- Comprehensive documentation: The community-maintained Biopython Tutorial and Cookbook provides extensive worked examples for research workflows.
Limits
- High-throughput sequencing performance: Pure Python parsing is slower than compiled C/Rust tools. Processing millions of reads in gigabyte-scale BAM or FASTQ files is best done with specialized tools like Samtools, SeqKit, or
pysam. - Tool wrapper deprecation: Several legacy command-line wrappers have been deprecated in favor of direct execution using Python’s
subprocessmodule. - No native variant caller: Biopython provides data structures for sequences and alignments, but does not provide end-to-end variant calling or read assembly algorithms.
Alternatives to Biopython
Depending on language requirements and data scale, researchers utilize several alternative toolkits:
| Tool / Package | Language | Core Focus | Best Used For | Governance / Maintenance |
|---|---|---|---|---|
| Biopython | Python | Sequence I/O, NCBI APIs, PDB parsing, alignments | General bioinformatics scripting, pipeline automation | Open Bioinformatics Foundation (OBF); active |
| BioPerl | Perl | Genomic feature parsing, sequence manipulation | Legacy enterprise pipelines, older institutional systems | Open Bioinformatics Foundation (OBF); maintenance |
| BioJava | Java | Macromolecular structures (MMTF, PDB), sequence algorithms | Enterprise laboratory information systems, high-throughput structural analysis | Open Bioinformatics Foundation (OBF); active |
| scikit-bio | Python | Microbial ecology, phylogenetic distances, diversity metrics | Metagenomics, 16S amplicon analysis, community ecology | Independent academic community; active |
| SeqKit / Samtools | Go / C | High-speed command-line sequence filtering, BAM/SAM indexing | Raw Next-Generation Sequencing (NGS) read filtering and alignment indexing | HTSlib / academic developer teams; active |
Frequently asked questions
Is Biopython free for commercial research and pharmaceutical development?
Yes. Biopython is distributed under the Biopython License Agreement, a BSD-style open-source license. Commercial laboratories, biotechnology firms, and pharmaceutical companies can use, modify, and incorporate Biopython into internal pipelines and commercial products without paying royalties.
What is the Biopython Tutorial and Cookbook, and where is it maintained?
The Biopython Tutorial and Cookbook is the official documentation guide for the package. Authored and maintained by core developers, it provides recipes and code examples across all major modules. It is hosted directly on the official Biopython website.
Does Biopython support Python 2?
No. Biopython discontinued Python 2 support with the release of version 1.77 in 2020. Modern releases require Python 3.9 or higher and utilize Python 3 language features, type hints, and updated standard library modules.
How does Biopython handle NCBI Entrez rate limits?
NCBI limits automated requests to its Entrez E-utilities servers. Biopython requires researchers to provide an email address via Entrez.email. Unauthenticated requests are capped at 3 queries per second; providing an NCBI API key via Entrez.api_key increases the limit to 10 queries per second.
Can Biopython directly manipulate raw Next-Generation Sequencing BAM and VCF files?
Biopython handles sequence records and basic alignments, but is not designed for indexing or querying massive binary BAM or compressed VCF files. For high-volume sequencing files, bioinformaticians typically use dedicated C-bound libraries such as pysam or cyvcf2.
Sources
- Cock PA, Antao T, Chang JT, Chapman BA, Cox CJ, Dalke A, Friedberg I, Hamelryck T, Kauff F, Wilczynski B, de Hoon MJ. Biopython: freely available Python tools for computational molecular biology and bioinformatics. Bioinformatics, 2009 Jun 1;25(11):1422-1423. doi: 10.1093/bioinformatics/btp163. PMC2682512. URL:
https://pmc.ncbi.nlm.nih.gov/articles/PMC2682512/(Read 2026-11-07). - Biopython Project. Biopython Tutorial and Cookbook. Jeff Chang, Brad Chapman, Iddo Friedberg, Thomas Hamelryck, Michiel de Hoon, Peter Cock, Tiago Antao, Eric Talevich, Bartek Wilczynski. URL:
https://biopython.org/DIST/docs/tutorial/Tutorial.html(Read 2026-11-07). - Open Bioinformatics Foundation (OBF). Biopython Project Profile and Governance. URL:
https://www.open-bio.org/projects/biopython/(Read 2026-11-07). - Python Packaging Authority (PyPA). Biopython on PyPI: Package Metadata and Distribution. URL:
https://pypi.org/project/biopython/(Read 2026-11-07).







