skillfed

pysam

Package for reading, manipulating, and writing genomic data

pysam v0.24.0 1.3M downloads/30d#4,103 on PyPI905
Permissive license MIT License Active released

What it is and what it does

pysam is a Python wrapper around HTSlib, the C library underlying samtools and bcftools, that lets you read and write genomic sequence data in standard formats (SAM, BAM, CRAM, VCF, BCF, BED, GFF, GTF, FASTA, FASTQ). It provides both low-level access to HTSlib's C API via Cython and a high-level Python interface for working with genomic data, including support for compression and random access through indexing.

The package is widely used in bioinformatics pipelines and genomic analysis workflows. It has no runtime dependencies beyond HTSlib itself (bundled in the wheel), making it straightforward to integrate into data processing scripts. Active maintenance and broad platform support (macOS, Linux) with prebuilt wheels for Python 3.10–3.13 mean installation is typically frictionless on supported systems.

Use it for:

  • Parse and filter SAM/BAM files in a genomic analysis pipeline without calling samtools as a subprocess
  • Extract specific genomic regions or read alignments from indexed VCF/BCF files for variant analysis
  • Convert between genomic file formats (e.g., BAM to CRAM) programmatically within a Python workflow
  • Access samtools and bcftools functionality directly from Python without shell subprocess overhead
  • Build custom bioinformatics tools that need to read FASTA/FASTQ sequences and alignment data

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

pysam reads, manipulates, and writes genomic data files (SAM/BAM/CRAM/VCF/BCF/BED/GFF/GTF/FASTA/FASTQ) and provides access to samtools and bcftools command-line functionality through a Python wrapper around HTSlib.

Yes. pysam is actively maintained, has no runtime dependencies, carries a permissive MIT license, and is essential for any Python-based genomic data processing. Medium install friction is offset by prebuilt wheels for modern Python versions and the absence of external runtime requirements. No known vulnerabilities.

Install

pysam on PyPI

pip

pip install pysam

uv

uv add pysam

poetry

poetry add pysam

Installing pysam

Before you install

Medium install friction due to compiled C extensions via Cython wrapping HTSlib; prebuilt wheels available for common Python versions (3.10–3.13) and platforms (macOS, Linux, musl). Active maintenance with last commit 2026-08-10.

License in practice

MIT License (permissive) allows use in proprietary and open-source projects with minimal restrictions; attribution required.

Quickstart

import pysam

# Open and read a BAM file
bamfile = pysam.AlignmentFile('example.bam', 'rb')
for read in bamfile:
    print(read.query_name, read.query_sequence)
bamfile.close()

Requires HTSlib C library and development headers; pysam is a compiled extension and cannot be used without a compatible binary wheel or build environment.

Verify before relying

  • Whether the package works on Windows (classifiers list MacOS/POSIX/Unix but no Windows wheel evidence)
  • Performance characteristics for large genomic datasets
  • Exact HTSlib version bundled or required

Package facts

License MIT License (permissive)
Python support supports the current Python release (>=3.8)
Install friction medium — platform-specific wheel
Runtime dependencies none
Maintenance actively maintained — 109 days since the last release
Last repo commit
First released
Downloads 1,291,977/month — #4,103 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: pysam-0.24.0-cp310-cp310-macosx_10_9_x86_64.whl; pysam-0.24.0-cp310-cp310-macosx_11_0_arm64.whl; pysam-0.24.0-cp310-cp310-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl; pysam-0.24.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl; pysam-0.24.0-cp310-cp310-musllinux_1_2_aarch64.whl; pysam-0.24.0-cp310-cp310-musllinux_1_2_x86_64.whl; pysam-0.24.0-cp311-cp311-macosx_10_9_x86_64.whl; pysam-0.24.0-cp311-cp311-macosx_11_0_arm64.whl; pysam-0.24.0-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl; pysam-0.24.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl; pysam-0.24.0-cp311-cp311-musllinux_1_2_aarch64.whl; pysam-0.24.0-cp311-cp311-musllinux_1_2_x86_64.whl; pysam-0.24.0-cp312-cp312-macosx_10_13_x86_64.whl; pysam-0.24.0-cp312-cp312-macosx_11_0_arm64.whl; pysam-0.24.0-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl; pysam-0.24.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl; pysam-0.24.0-cp312-cp312-musllinux_1_2_aarch64.whl; pysam-0.24.0-cp312-cp312-musllinux_1_2_x86_64.whl; pysam-0.24.0-cp313-cp313-macosx_10_13_x86_64.whl; pysam-0.24.0-cp313-cp313-macosx_11_0_arm64.whl

Development Status :: 4 - BetaIntended Audience :: DevelopersIntended Audience :: Science/ResearchOperating System :: MacOSOperating System :: POSIXOperating System :: UnixProgramming Language :: PythonTopic :: Scientific/EngineeringTopic :: Software Development

Tags

genomic file parsingSAM BAM VCF file handlingbioinformatics data processingHTSlib Python wrappergenomic sequence analysisNGS data manipulationsamtools bcftools Python
bioinformaticsgenomicshtSlib-wrapper

More Software Development packages