Skip to main content

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")
>>>
>>> sorted(file.name for file in directory.iterdir())
['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.

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")
...     writer.columns == Columns.VCF
True

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:
...     handle.readline()
'chr1\t100\t200\tgene-a\n'

>>> with pybgzf.IndexedReader(path) as reader:
...     list(reader.query("chr1", 180, 190))
['chr1\t100\t200\tgene-a', 'chr1\t150\t300\tgene-b']

Benchmarks

Writing 200 MB of BED lines at level 6, then reading them back, on an Apple M3 Max with benchmarks/benchmark.py:

Command Seconds MB/s
gzip (stdlib) 4.80 42
pybgzf, 1 thread, .tbi 1.84 109
pybgzf, 4 threads, .tbi 0.43 466
pybgzf, 16 threads, .tbi 0.31 641
bgzip -@1 then tabix 3.01 66
bgzip -@4 then tabix 1.31 153
bgzip -@16 then tabix 0.90 222
lines from gzip.open (stdlib) 0.66 303
lines from reader, 1 thread 0.44 456
lines from reader, 4 threads 0.30 671
bytes from BgzfReader, 16 threads 0.03 7608
bgzip -d -@16 0.03 7652

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.1.0

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.1.0
File Size Uploaded
pybgzf-0.1.0.tar.gz 145.6 kB Details

Built distributions (wheels)

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

Total release size: 4.5 MB

Release files / pybgzf-0.1.0.tar.gz

Download URL pybgzf-0.1.0.tar.gz
Size 145.6 kB
Tags Source
SHA-256 checksum
How to use checksums
bef6776c0f8842272bc6820837893365975a583bbfd99d38ea357af50fe1d6c9
BLAKE2b-256 checksum
How to use checksums
3f46206f98f344e1bdb15c1b3acb74c243a67e7bf9dfae5471ec218cd04a29e4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 30, 2026.

Transparency log

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

Download URL pybgzf-0.1.0-cp311-abi3-win_amd64.whl
Size 453.9 kB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
a71d5e42fb56450a9cf667281eff02f04e9847720b4b47fb18ee4926813c4e02
BLAKE2b-256 checksum
How to use checksums
05bfd1a54f380c0248601ec43c010a67f3cc9ca465d3d1f05d77063d06cf373c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 30, 2026.

Transparency log

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

Download URL pybgzf-0.1.0-cp311-abi3-musllinux_1_2_x86_64.whl
Size 828.2 kB
Tags CPython 3.11 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
804d39764fd96352d1a223e2c20243e169deac31164b01f9d843d94d6a870aae
BLAKE2b-256 checksum
How to use checksums
64d0d355952d4e6456bbcf500b3d6311e34896b26558a013bb171d6ecd1a6d9c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 30, 2026.

Transparency log

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

Download URL pybgzf-0.1.0-cp311-abi3-musllinux_1_2_aarch64.whl
Size 779.8 kB
Tags CPython 3.11 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
9ce22387cab8034918bf5c7649afebfee21a64c17f94003fc635c69e825a1cf6
BLAKE2b-256 checksum
How to use checksums
7a27469584492728c98891ec5fd9efbff1fd1d09f337142630422c0837460958
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 30, 2026.

Transparency log

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

Download URL pybgzf-0.1.0-cp311-abi3-manylinux_2_28_aarch64.whl
Size 606.6 kB
Tags CPython 3.11 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
1ac15c3879f3fbc2811fd998a15564419bb71a52776b6a607df6ed340f4d83cf
BLAKE2b-256 checksum
How to use checksums
884dd034af3d98c589d2c00d2f9a43c99525d0abeebb42e879ba1b40d1534361
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 30, 2026.

Transparency log

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

Download URL pybgzf-0.1.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 613.3 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
8039d541e4733e9643d9d82d92dc923a49fb1fd1bf4d8f328688b14f6d201d9f
BLAKE2b-256 checksum
How to use checksums
bba68c6c9bbb2d610a0de2f8d02ef2f745d8c6fcd4976a46e5a18698a12a65ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 30, 2026.

Transparency log

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

Download URL pybgzf-0.1.0-cp311-abi3-macosx_11_0_arm64.whl
Size 533.0 kB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
1ca4702f28a07de54e62e2971cbeda1853dc48c60d76bc70fa7f584818af59a8
BLAKE2b-256 checksum
How to use checksums
89fa9005bfb5896df0039925e22438a078754c2a1e11e177c91132f836c4a2e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 30, 2026.

Transparency log

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

Download URL pybgzf-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl
Size 557.4 kB
Tags CPython 3.11 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
d3d2792d5b4332c6c936881b330b0aed17b1ae8f39b6da849aca96bf8d48a47c
BLAKE2b-256 checksum
How to use checksums
1eed31bc8a76707d225d5b825eb9f37d8bf2a4d191fcd89cb2b1a05660206116
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 30, 2026.

Transparency log

Release history Release notifications | RSS feed

0.1.1

8 release files

This release

0.1.0 This release

8 release files

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