--- id: pysam version: "0.24.0" license: MIT License license_treatment: permissive maintenance: active --- # pysam — Package for reading, manipulating, and writing genomic data License: permissive · Maintenance: active · Downloads: 1.3M/mo ## 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 above — 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 pip install pysam uv add pysam 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_current - Install friction: medium - Maintenance: active - Downloads: 1.3M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags genomic file parsing, SAM BAM VCF file handling, bioinformatics data processing, HTSlib Python wrapper, genomic sequence analysis, NGS data manipulation, samtools bcftools Python, bioinformatics, genomics, htSlib-wrapper [View on SkillFed](https://skillfed.io/packages/pysam) · [View on PyPI](https://pypi.org/project/pysam/)