pybgzf
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.
pybgzf.BGZF_SUFFIXES holds the file name suffixes of BGZF files, for deciding when to write one:
>>> pybgzf.BGZF_SUFFIXES
('.gz', '.bgz', '.bgzf')
>>> path.name.endswith(pybgzf.BGZF_SUFFIXES)
True
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']
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.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pybgzf-0.2.0.tar.gz | 147.3 kB | With provenance | Details for pybgzf-0.2.0.tar.gz |
Built distributions (wheels)
Total release size: 4.5 MB
Release files / pybgzf-0.2.0.tar.gz
| Download URL | pybgzf-0.2.0.tar.gz |
|---|---|
| Size | 147.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c5c811bce3fe8f4106435c5571ebfa007c736eda937f19ed1f4bc409db286601
|
|
BLAKE2b-256 checksum How to use checksums |
febec20875c293b208b9bbfcb4492198d25a91c31958b595709361820254da60
|
| 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 Oct 6, 2026.
Transparency logRelease files / pybgzf-0.2.0-cp311-abi3-win_amd64.whl
| Download URL | pybgzf-0.2.0-cp311-abi3-win_amd64.whl |
|---|---|
| Size | 455.1 kB |
| Tags | CPython 3.11 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
1ec13b22e278b8ac5faa60a0350bc3d327324face0e0a2b737fa7f8b9a33cda1
|
|
BLAKE2b-256 checksum How to use checksums |
f8bd396626815c9d0383bee5e1a5652a7d1c8e4b769ad75f529cbb3d01ca5c41
|
| 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 Oct 6, 2026.
Transparency logRelease files / pybgzf-0.2.0-cp311-abi3-musllinux_1_2_x86_64.whl
| Download URL | pybgzf-0.2.0-cp311-abi3-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 831.5 kB |
| Tags | CPython 3.11 Linux musl 1.2+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
8bc20d26cc90643612b7e053937212cc6e50fca7a118d550d68970631de3b10e
|
|
BLAKE2b-256 checksum How to use checksums |
c06fc3978d23e1dae2afa3654b7e1703051b26509826ecb45a988856ce7dac3e
|
| 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 Oct 6, 2026.
Transparency logRelease files / pybgzf-0.2.0-cp311-abi3-musllinux_1_2_aarch64.whl
| Download URL | pybgzf-0.2.0-cp311-abi3-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 783.6 kB |
| Tags | CPython 3.11 Linux musl 1.2+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
d925845b9105882b083202928c6893b12b3351c224accdbda937235cafc30877
|
|
BLAKE2b-256 checksum How to use checksums |
d999e4f6a56f7833b521d44312bced6a5cfd7b88ec8d0cebf5067c8f0f26efb9
|
| 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 Oct 6, 2026.
Transparency logRelease files / pybgzf-0.2.0-cp311-abi3-manylinux_2_28_aarch64.whl
| Download URL | pybgzf-0.2.0-cp311-abi3-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 610.1 kB |
| Tags | CPython 3.11 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
279bf6962e1b57bc8110eacf48ef5278030abf5123a9b62157558d378751bac7
|
|
BLAKE2b-256 checksum How to use checksums |
399606bff88fa1974b638465038d753a12a13d18cd2815a7f375ebb007ddb202
|
| 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 Oct 6, 2026.
Transparency logRelease files / pybgzf-0.2.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | pybgzf-0.2.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 616.7 kB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
df06186f55979b767e2a33115f510c7f20729ac791848bf3c8e4deef6448fc28
|
|
BLAKE2b-256 checksum How to use checksums |
9b5a721592d1fd7160cdbd67d2122c9b02c6ff289f537568920747be3db288ec
|
| 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 Oct 6, 2026.
Transparency logRelease files / pybgzf-0.2.0-cp311-abi3-macosx_11_0_arm64.whl
| Download URL | pybgzf-0.2.0-cp311-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 534.0 kB |
| Tags | CPython 3.11 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
cc35f2fb27f566927f1992d02c6a71187854ec6da81e8e5586234dbfa75b48c2
|
|
BLAKE2b-256 checksum How to use checksums |
53b6df2a0f80dea3fb4f37247adf69c342e66585c5052728e4796a1e8f7240f9
|
| 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 Oct 6, 2026.
Transparency logRelease files / pybgzf-0.2.0-cp311-abi3-macosx_10_12_x86_64.whl
| Download URL | pybgzf-0.2.0-cp311-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 559.4 kB |
| Tags | CPython 3.11 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
50b39883d7b58ac359236cc8b86c18fa5760185d3c8c5f17a468f3d54cef06d5
|
|
BLAKE2b-256 checksum How to use checksums |
2b461837f8e2606a7c4f2046b04d9b17fe6379bbb5a6a6750d81d239f1b391d1
|
| 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 Oct 6, 2026.
Transparency logSecurity for pybgzf 0.2.0
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.
Attestation for pybgzf-0.2.0.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 Oct 6, 2026.
Transparency logA 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.