skillfed

cyvcf2

fast vcf parsing with cython + htslib

cyvcf2 v0.34.0 217.2K downloads/30d#9,361 on PyPI446
Permissive license MIT Active released

What it is and what it does

cyvcf2 is a high-performance Python interface to VCF and BCF genomic variant files, built as a Cython wrapper around the C library htslib. It parses variant records and returns their attributes—chromosome, position, reference and alternate alleles, genotypes, depths, and custom INFO/FORMAT fields—as numpy arrays ready for immediate analysis. The package supports region-based queries on indexed files and works with Python 3.9 and later.

Typical use involves iterating over variants in a file, extracting genotype or depth information as numpy arrays, and filtering or aggregating them downstream. A key design detail is that numpy arrays returned by attributes like `gt_ref_depths` are backed by the underlying C data structure, so they become invalid once the variant object goes out of scope; users must explicitly copy arrays they wish to persist. The package includes a command-line tool for basic VCF inspection and filtering.

Use it for:

  • Filter variants by allele frequency or quality thresholds extracted from INFO fields and genotype depths.
  • Extract genotype matrices or depth arrays from large VCF files for population genetics or association studies.
  • Query specific genomic regions in indexed VCF/BCF files without loading the entire file into memory.
  • Convert VCF records to numpy arrays for downstream machine learning or statistical analysis pipelines.
  • Rapidly scan VCF files from the command line to inspect headers, sample counts, or variant statistics.

Worth the install?

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

cyvcf2 is a Cython wrapper around htslib that parses VCF and BCF genomic variant files at speed, including region-based queries, and returns numpy arrays for immediate downstream analysis.

Yes. cyvcf2 is actively maintained, widely used in bioinformatics, has no known vulnerabilities, and offers permissive licensing. Binary wheels make installation frictionless for most users. Install it if you need to parse VCF or BCF files in Python and want speed and direct numpy integration; avoid it only if you cannot tolerate the C compiler requirement for source builds or the array-lifetime gotcha.

Install

cyvcf2 on PyPI

pip

pip install cyvcf2

uv

uv add cyvcf2

poetry

poetry add cyvcf2

Installing cyvcf2

Before you install

Binary wheels are available for Python 3.9–3.13 on macOS, Linux, and Windows, so most users will install without compilation. Medium friction remains because source builds require htslib and a C compiler; the package is actively maintained with a recent release.

License in practice

MIT license permits commercial and private use with minimal restrictions; you may use, modify, and distribute cyvcf2 freely as long as you include the license notice.

Quickstart

pip install cyvcf2

from cyvcf2 import VCF

for variant in VCF('some.vcf.gz'):
    print(variant.CHROM, variant.start, variant.REF, variant.ALT)
    dp = variant.format('DP')  # numpy array of depth per sample

Requires htslib >= 1.10 (bundled in wheels); source builds need a C compiler and htslib development headers.

Verify before relying

  • Whether the numpy array backing behavior (arrays becoming invalid when variant goes out of scope) is a practical concern for typical workflows.
  • Performance characteristics on very large VCF files or with many concurrent region queries.

Package facts

License MIT (permissive)
Python support supports the current Python release (>=3.9)
Install friction medium — platform-specific wheel
Runtime dependencies 3 — numpy, coloredlogs, click
Maintenance actively maintained — 50 days since the last release
Last repo commit
First released
Downloads 217,227/month — #9,361 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: cyvcf2-0.34.0-cp310-cp310-macosx_10_9_x86_64.whl; cyvcf2-0.34.0-cp310-cp310-macosx_11_0_arm64.whl; cyvcf2-0.34.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl; cyvcf2-0.34.0-cp310-cp310-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl; cyvcf2-0.34.0-cp310-cp310-musllinux_1_2_x86_64.whl; cyvcf2-0.34.0-cp311-cp311-macosx_10_9_x86_64.whl; cyvcf2-0.34.0-cp311-cp311-macosx_11_0_arm64.whl; cyvcf2-0.34.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl; cyvcf2-0.34.0-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl; cyvcf2-0.34.0-cp311-cp311-musllinux_1_2_aarch64.whl; cyvcf2-0.34.0-cp311-cp311-musllinux_1_2_x86_64.whl; cyvcf2-0.34.0-cp312-cp312-macosx_10_13_x86_64.whl; cyvcf2-0.34.0-cp312-cp312-macosx_11_0_arm64.whl; cyvcf2-0.34.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl; cyvcf2-0.34.0-cp312-cp312-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl; cyvcf2-0.34.0-cp312-cp312-musllinux_1_2_aarch64.whl; cyvcf2-0.34.0-cp312-cp312-musllinux_1_2_x86_64.whl; cyvcf2-0.34.0-cp313-cp313-macosx_10_13_x86_64.whl; cyvcf2-0.34.0-cp313-cp313-macosx_11_0_arm64.whl; cyvcf2-0.34.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Development Status :: 5 - Production/StableIntended Audience :: Science/ResearchOperating System :: MacOSOperating System :: Microsoft :: WindowsOperating System :: POSIX :: LinuxProgramming Language :: CythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyTopic :: Scientific/Engineering :: Bio-Informatics

Tags

vcf parsing pythonbcf file readervariant call formatgenomic variant parsinghtslib wrapperregion query vcffast vcf reader
bioinformaticsgenomicsvcf-parsing

More Bio-Informatics packages