pysam: htslib interface for python
- Author:
Andreas Heger, John Marshall, Kevin Jacobs, and contributors
- Date:
Nov 25, 2025
- Version:
0.23.3
Pysam is a python module for reading, manipulating and writinggenomic data sets.
Pysam is a wrapper of thehtslib C-API and provides facilities toread and write SAM/BAM/VCF/BCF/BED/GFF/GTF/FASTA/FASTQ files as wellas access to the command line functionality of thesamtools andbcftools packages. The module supports compression and random accessthrough indexing.
This module provides a low-level wrapper around thehtslib C-API asusing cython and a high-level, pythonic API for convenient access tothe data within genomic file formats.
The current version wrapshtslib-1.22.1,samtools-1.22.1, andbcftools-1.22.
To install the latest release, type:
pipinstallpysam
See theInstallation notes for details.
This module is unrelated toNREL-PySAM, which wraps the National RenewableEnergy Laboratory’s System Advisor Model.
Contents
- Introduction
- API
- Working with BAM/CRAM/SAM-formatted files
- Using samtools and bcftools commands within Python
- Working with tabix-indexed files
- Working with VCF/BCF formatted files
- Extending pysam
- Installing pysam
- FAQ
- How should I cite pysam
- Is pysam thread-safe?
- pysam coordinates are wrong
- Calling pysam.fetch() confuses existing iterators
- AlignmentFile.fetch does not show unmapped reads
- I can’t call AlignmentFile.fetch on a file without an index
- BAM files with a large number of reference sequences are slow
- Weirdness with spliced reads in samfile.pileup(chr,start,end) given spliced alignments from an RNA-seq bam file
- I can’t edit quality scores in place
- Why is there no SNPCaller class anymore?
- I get an error ‘PileupProxy accessed after iterator finished’
- Pysam won’t compile
- ImportError: cannot import name csamtools
- Developer’s guide
- Release notes
- Release 0.23.3
- Release 0.23.2
- Release 0.23.1
- Release 0.23.0
- Release 0.22.1
- Release 0.22.0
- Release 0.21.0
- Release 0.20.0
- Release 0.19.1
- Release 0.19.0
- Release 0.18.0
- Release 0.17.0
- Release 0.16.0
- Release 0.15.4
- Release 0.15.3
- Release 0.15.2
- Release 0.15.1
- Release 0.15.0
- Release 0.14.1
- Release 0.14.0
- Release 0.13.0
- Release 0.12.0.1
- Release 0.12.0
- Release 0.11.2.2
- Release 0.11.2.1
- Release 0.11.2
- Release 0.11.1
- Release 0.11.0
- Release 0.10.0
- Release 0.9.1
- Release 0.9.0
- Release 0.8.4
- Release 0.8.3
- Release 0.8.2.1
- Release 0.8.2
- Release 0.8.1
- Release 0.8.0
- Release 0.7.8
- Release 0.7.7
- Release 0.7.6
- Release 0.7.5
- Release 0.7.4
- Release 0.7.3
- Release 0.7.2
- Release 0.7.1
- Release 0.7
- Release 0.6
- Release 0.5
- Release 0.4
- Release 0.3
- Benchmarking
- Glossary
Indices and tables
Contents:
References
The Sequence Alignment/Map format and SAMtools.Li H, Handsaker B, Wysoker A, Fennell T, Ruan J, Homer N, Marth G, Abecasis G, Durbin R; 1000 Genome Project Data Processing Subgroup.Bioinformatics. 2009 Aug 15;25(16):2078-9.Epub 2009 Jun 8btp352.PMID:19505943.
See also
- Information about htslib
- The samtools homepage
- The cython C-extensions for python
- The python language