Skip to main content

Banner for pybgzf


Build Status Python Versions License: MIT Language

Streaming BGZF compression with on-the-fly tabix and CSI indexing.

Install with pip or uv:

pip install pybgzf

Introduction

pybgzf writes blocked gzip (BGZF) files from Python and builds their tabix (.tbi) or CSI (.csi) index while it writes, so there is no second pass with tabix. Its core is Rust: blocks are compressed with the multithreaded, libdeflate-backed bgzf crate and indexes are written with noodles. It needs neither pysam nor htslib.

Quick Start

Write sorted BED lines as text and the index appears next to the file on close:

from pathlib import Path
from tempfile import mkdtemp

import pybgzf
from pybgzf import Columns, IndexFormat

directory = Path(mkdtemp())
path = directory / "features.bed.gz"

with pybgzf.writer(path, index=IndexFormat.TBI, columns=Columns.BED) as handle:
    handle.write("chr1\t100\t200\tgene-a\n")
    handle.write("chr1\t150\t300\tgene-b\n")
    handle.write("chr2\t10\t20\tgene-c\n")

files = sorted(file.name for file in directory.iterdir())

assert files == ["features.bed.gz", "features.bed.gz.tbi"]

The output is ordinary BGZF, so gzip -d, bgzip -d, and tabix features.bed.gz chr1:120-160 all read it. pybgzf.BGZF_SUFFIXES holds the file name suffixes of BGZF files, for deciding when to write one:

assert pybgzf.BGZF_SUFFIXES == (".gz", ".bgz", ".bgzf")
assert path.name.endswith(pybgzf.BGZF_SUFFIXES)

Stream bytes to a pipe or any binary file object, with columns inferred from the content:

import io

stream = io.BytesIO()

with pybgzf.BgzfWriter(stream, threads=4, index=IndexFormat.CSI, index_path=directory / "calls.csi", columns=pybgzf.INFER) as writer:
    writer.write(b"##fileformat=VCFv4.3\n")
    columns = writer.columns

assert columns == Columns.VCF

Read the BED file back on several threads, or query a region with 0-based, half-open coordinates:

with pybgzf.reader(path, threads=4) as handle:
    line = handle.readline()

assert line == "chr1\t100\t200\tgene-a\n"

with pybgzf.IndexedReader(path) as reader:
    lines = list(reader.query("chr1", 180, 190))

assert lines == ["chr1\t100\t200\tgene-a", "chr1\t150\t300\tgene-b"]

Development and Testing

See the contributing guide for more information.

The multithreaded, position-tracking writer is adapted from fgumi, and indexing follows htslib; see NOTICE.

Metadata

Release files for pybgzf 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pybgzf 0.2.1
File Size Uploaded Provenance Actions
pybgzf-0.2.1.tar.gz 147.4 kB With provenance Details for pybgzf-0.2.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for pybgzf 0.2.1
File Actions
pybgzf-0.2.1-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details for pybgzf-0.2.1-cp311-abi3-win_amd64.whl
pybgzf-0.2.1-cp311-abi3-musllinux_1_2_x86_64.whl CPython 3.11 abi3 Linux musl 1.2+ x86-64 Details for pybgzf-0.2.1-cp311-abi3-musllinux_1_2_x86_64.whl
pybgzf-0.2.1-cp311-abi3-musllinux_1_2_aarch64.whl CPython 3.11 abi3 Linux musl 1.2+ ARM64 Details for pybgzf-0.2.1-cp311-abi3-musllinux_1_2_aarch64.whl
pybgzf-0.2.1-cp311-abi3-manylinux_2_28_aarch64.whl CPython 3.11 abi3 Linux glibc 2.28+ ARM64 Details for pybgzf-0.2.1-cp311-abi3-manylinux_2_28_aarch64.whl
pybgzf-0.2.1-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.11 abi3 Linux glibc 2.17+ x86-64 Details for pybgzf-0.2.1-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
pybgzf-0.2.1-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details for pybgzf-0.2.1-cp311-abi3-macosx_11_0_arm64.whl
pybgzf-0.2.1-cp311-abi3-macosx_10_12_x86_64.whl CPython 3.11 abi3 macOS 10.12+ x86-64 Details for pybgzf-0.2.1-cp311-abi3-macosx_10_12_x86_64.whl

Total release size: 4.6 MB

Release files / pybgzf-0.2.1.tar.gz

Download URL pybgzf-0.2.1.tar.gz
Size 147.4 kB
Tags Source
SHA-256 checksum
How to use checksums
3d7514c744934289397656d003d22d77b9ae144464d111907f1c18d91bcf3341
BLAKE2b-256 checksum
How to use checksums
fe98f4e755aeded067f625431b5c2a18685b3f8f520a79c778d26dd21cd6a61b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

Release files / pybgzf-0.2.1-cp311-abi3-win_amd64.whl

Download URL pybgzf-0.2.1-cp311-abi3-win_amd64.whl
Size 461.9 kB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
7e012cdf4151ec3d925c9a2cdfc6b0b175e15ae7978bb38384da6dce286b8567
BLAKE2b-256 checksum
How to use checksums
331406f35ab9806821a3c0981f0025a404ea8d065f3b825d507b02838912b7c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

Release files / pybgzf-0.2.1-cp311-abi3-musllinux_1_2_x86_64.whl

Download URL pybgzf-0.2.1-cp311-abi3-musllinux_1_2_x86_64.whl
Size 834.5 kB
Tags CPython 3.11 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
6d399dea11c2e86d8c6028102b0ed21571dccfef85c337474558b6978b0d2cbd
BLAKE2b-256 checksum
How to use checksums
fa1aa7eea01405fd4f4cfb43ad7b67c038bb8ae105fccfec3a0807be595781e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

Release files / pybgzf-0.2.1-cp311-abi3-musllinux_1_2_aarch64.whl

Download URL pybgzf-0.2.1-cp311-abi3-musllinux_1_2_aarch64.whl
Size 787.2 kB
Tags CPython 3.11 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
99b44f3c6e1ae57428149a0b3db8b19198b1c19aca32bd57fd6f9c903b0cbcb0
BLAKE2b-256 checksum
How to use checksums
6ec7b55bbe8bf1fcb2bc3884728a3c5a449e6d911398addd2dfeac95aa2b4a3c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

Release files / pybgzf-0.2.1-cp311-abi3-manylinux_2_28_aarch64.whl

Download URL pybgzf-0.2.1-cp311-abi3-manylinux_2_28_aarch64.whl
Size 612.4 kB
Tags CPython 3.11 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
40149859492edaf9f3d0a60a41648fb03cad37503a396635ef09c558bb1e4802
BLAKE2b-256 checksum
How to use checksums
f30a7b5cb3dd7f969981368bfc7bda2a64d0eb4242f3bd0a39b5cc59ffc7b3f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

Release files / pybgzf-0.2.1-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL pybgzf-0.2.1-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 619.7 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
07704e3c8940f7e2d446965fe60e656fd0970cd5114058ebd742e8dce4215ca6
BLAKE2b-256 checksum
How to use checksums
1ba058b52140b8aa189d307d4f4e0404bceb89701ad987abd50c1dad4324a1e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

Release files / pybgzf-0.2.1-cp311-abi3-macosx_11_0_arm64.whl

Download URL pybgzf-0.2.1-cp311-abi3-macosx_11_0_arm64.whl
Size 539.6 kB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
f1f07e02e9d01fa782868c9844d2b756eebc99b314b56daedf01307c113c3f50
BLAKE2b-256 checksum
How to use checksums
a0683007ec160adbe6fea92ca282ca6970dc3cc7c3892583fd747a41b120c9ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

Release files / pybgzf-0.2.1-cp311-abi3-macosx_10_12_x86_64.whl

Download URL pybgzf-0.2.1-cp311-abi3-macosx_10_12_x86_64.whl
Size 559.1 kB
Tags CPython 3.11 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
e5da554506c6c006459970cbf6c19e1df99de67e3f23a8e42c0f0fc759376f19
BLAKE2b-256 checksum
How to use checksums
53e7b334d451224e968b519748dc824dfc7cecab0fa514d3989922194c6e3a76
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

Security for pybgzf 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 8 files in this release have been uploaded with provenance metadata.

Select from 8 files

Attestation for pybgzf-0.2.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page