cyvcf2
fast vcf parsing with cython + htslib
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 cyvcf2uv
uv add cyvcf2poetry
poetry add cyvcf2Installing 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
Tags
More Bio-Informatics packages
NetworkX provides data structures and…
permissive · top 1,000 on PyPI
biopythonBiopython provides Python tools for…
unclear · top 5,000 on PyPI
firecrawl-pyClient library for the Firecrawl API that…
permissive · top 5,000 on PyPI
intervaltreeA self-balancing interval tree data structure…
permissive · top 5,000 on PyPI
albumentationsAlbumentations applies image transformations to…
permissive · top 5,000 on PyPI
PubChemPyPubChemPy is a Python wrapper around the…
permissive · top 5,000 on PyPI
pysampysam reads, manipulates, and writes genomic…
permissive · top 5,000 on PyPI
ifcopenshellIfcOpenShell is a Python library for parsing,…
copyleft · top 15,000 on PyPI
pythonvCard4Parse and generate RFC 6350-compliant vCard 4.0…
permissive · top 15,000 on PyPI
pyfaidxProvides fast random access to subsequences in…
permissive · top 15,000 on PyPI
gtfparseParses GTF (gene transfer format) files into…
permissive · top 15,000 on PyPI
pyrangesPyRanges provides efficient querying and…
permissive · top 15,000 on PyPI
cyseqcyseq provides a Cython-optimized…
permissive · top 15,000 on PyPI
CythonCython is a source code translator that…
permissive · top 1,000 on PyPI
pyxDamerauLevenshteinComputes Damerau-Levenshtein edit distance…
permissive · top 15,000 on PyPI
bioA command-line toolkit that simplifies common…
permissive · top 5,000 on PyPI