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']

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.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.1.1
File Size Uploaded
pybgzf-0.1.1.tar.gz 145.9 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for pybgzf 0.1.1
File
pybgzf-0.1.1-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details
pybgzf-0.1.1-cp311-abi3-musllinux_1_2_x86_64.whl CPython 3.11 abi3 Linux musl 1.2+ x86-64 Details
pybgzf-0.1.1-cp311-abi3-musllinux_1_2_aarch64.whl CPython 3.11 abi3 Linux musl 1.2+ ARM64 Details
pybgzf-0.1.1-cp311-abi3-manylinux_2_28_aarch64.whl CPython 3.11 abi3 Linux glibc 2.28+ ARM64 Details
pybgzf-0.1.1-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.1-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details
pybgzf-0.1.1-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.1.tar.gz

Download URL pybgzf-0.1.1.tar.gz
Size 145.9 kB
Tags Source
SHA-256 checksum
How to use checksums
4ff21a23f2dbabd0f953c1091aeb6b086869853859ef841eba0cb0f094ca9cf2
BLAKE2b-256 checksum
How to use checksums
c3b7d0c19c6b2cabe693315addc98e3f93929b38696c109b1c21e689aa926f13
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.1-cp311-abi3-win_amd64.whl

Download URL pybgzf-0.1.1-cp311-abi3-win_amd64.whl
Size 453.9 kB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
e82cf94e0285c158a220ad60c3e6f3cf9bf3c25e140d2b648a87a01b0657bf00
BLAKE2b-256 checksum
How to use checksums
57241a11cafa50dc2b0711b00e275b97d65d3e632f720982830e5a034a85a390
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.1-cp311-abi3-musllinux_1_2_x86_64.whl

Download URL pybgzf-0.1.1-cp311-abi3-musllinux_1_2_x86_64.whl
Size 828.1 kB
Tags CPython 3.11 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
25c3400d4cd8935f0f1fbc6a71a06aab2b3ba4ae116c09485f13dcc933d8a0ee
BLAKE2b-256 checksum
How to use checksums
06e11acc7e5ae56d494d14d155ef446d3a3fd740370a2fead6753b06a9063ad9
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.1-cp311-abi3-musllinux_1_2_aarch64.whl

Download URL pybgzf-0.1.1-cp311-abi3-musllinux_1_2_aarch64.whl
Size 780.1 kB
Tags CPython 3.11 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
575e47e252cf7d3a30f2bef932fd517fbd8aeea1e89be457e0284b62315a84eb
BLAKE2b-256 checksum
How to use checksums
d116ac3b1cfb55441e54159d78b1a3294bdc0e63932166a9b28f96b92b30eeb9
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.1-cp311-abi3-manylinux_2_28_aarch64.whl

Download URL pybgzf-0.1.1-cp311-abi3-manylinux_2_28_aarch64.whl
Size 606.1 kB
Tags CPython 3.11 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
4b52d5dbebe86f86ce3391b9ee15d6700912a50b106895fa6a7668fec2b00a4a
BLAKE2b-256 checksum
How to use checksums
b3d433a9a1636e89780f6c2c3a868b20bca92649bc53d6a1ccc03d6c0cb67c62
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.1-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pybgzf-0.1.1-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 613.5 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
1aae2b8a6aaf9352d33e4e641dd77583bf211a559cec496b336097d367593d58
BLAKE2b-256 checksum
How to use checksums
1520bff1574c221b827a816b3b9b8f206fdf79478d2171660e4a99cbcaed8185
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.1-cp311-abi3-macosx_11_0_arm64.whl

Download URL pybgzf-0.1.1-cp311-abi3-macosx_11_0_arm64.whl
Size 532.8 kB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
23f8a768cdcbdcc13695c22a36e364831a3c6224f0838c4870ef5ac9188ecfec
BLAKE2b-256 checksum
How to use checksums
07c6eb1266cad3e7a9d6ff944688a03a5a8c540f4fde58765775b49eed54691b
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.1-cp311-abi3-macosx_10_12_x86_64.whl

Download URL pybgzf-0.1.1-cp311-abi3-macosx_10_12_x86_64.whl
Size 557.6 kB
Tags CPython 3.11 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
fb618f0713a6fe03778daa1fd559ec3d0c328928206827823814ed89e62d2af4
BLAKE2b-256 checksum
How to use checksums
6348364320e88d7faabd6c29c3c9a75d11a31cf5c45760ca049ed5a7e49d6edc
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

This release

0.1.1 This release

8 release files

0.1.0

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