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

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.2
File Size Uploaded
pybgzf-0.1.2.tar.gz 146.2 kB Details

Built distributions (wheels)

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

Download URL pybgzf-0.1.2.tar.gz
Size 146.2 kB
Tags Source
SHA-256 checksum
How to use checksums
53267a31b027c5d84823ed7d23ae152358d88d5cae392c459de6d929d7313b2e
BLAKE2b-256 checksum
How to use checksums
ab16dcd3f77a8c2ccc4b3b28c47ac8ace3ed2cbe7f13b5ba6aa1733dbb84dc94
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 4, 2026.

Transparency log

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

Download URL pybgzf-0.1.2-cp311-abi3-win_amd64.whl
Size 454.3 kB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
4f5697c8690be309b6f4696bec06d950360130541991d2976b167686de45f5e5
BLAKE2b-256 checksum
How to use checksums
e7c54ed0167314c623ffa4837d718ef19b51a571c6143fc6b8e4609b44b1de1a
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 4, 2026.

Transparency log

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

Download URL pybgzf-0.1.2-cp311-abi3-musllinux_1_2_x86_64.whl
Size 830.8 kB
Tags CPython 3.11 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
0968e4314b2065ddf8d3e71c13830918642608bdc454cb8ed575fa22fcd2e3e7
BLAKE2b-256 checksum
How to use checksums
8aa2f24c13cb52c7cfc63b3f1a4825f709bb1505563f172decd1ba5788975144
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 4, 2026.

Transparency log

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

Download URL pybgzf-0.1.2-cp311-abi3-musllinux_1_2_aarch64.whl
Size 783.1 kB
Tags CPython 3.11 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
9fd1f0ddd47fb7f8c275eddf7c858b6a30e5e8c199392fdffed8d1f5e706dd5a
BLAKE2b-256 checksum
How to use checksums
39f3882c0b1aa05899ecc22c32b2cd56e4ba7520ef8551efc6323fa868494d18
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 4, 2026.

Transparency log

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

Download URL pybgzf-0.1.2-cp311-abi3-manylinux_2_28_aarch64.whl
Size 609.4 kB
Tags CPython 3.11 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
5434328997a8df271fa1ddcc168629699d879e4dd737d28ad53403c566ad3241
BLAKE2b-256 checksum
How to use checksums
7ad3574f3e1ab0bc2ff957afc97d7eddae5a3d11ef45978c299153bde8bf98d7
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 4, 2026.

Transparency log

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

Download URL pybgzf-0.1.2-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 615.7 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
e1c428782b71297af77ad0c8c6b9284729dba64c57753841d5105ddfd4a8c846
BLAKE2b-256 checksum
How to use checksums
c08a280646f9533daff436abc5948a181b5154134972840c770866fe63e7da8c
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 4, 2026.

Transparency log

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

Download URL pybgzf-0.1.2-cp311-abi3-macosx_11_0_arm64.whl
Size 533.3 kB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
8c2fddf6d80cd5f68e2c88ae060ce90a5a8cee060d112ca7136501c438c51037
BLAKE2b-256 checksum
How to use checksums
f6b6fc4e04f1070512f8783ad708247c68154e327f63c7c4ffc746d2f75abaca
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 4, 2026.

Transparency log

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

Download URL pybgzf-0.1.2-cp311-abi3-macosx_10_12_x86_64.whl
Size 558.5 kB
Tags CPython 3.11 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
ae8e7a76ef4fea8988f650b8e726a5e1e11bc8909cd1a4d2211be4398ba3dd75
BLAKE2b-256 checksum
How to use checksums
180800805caeff4f9008c8dc344db91a797a7b05f927a9c1ac779960bc1e23e8
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 4, 2026.

Transparency log

Release history Release notifications | RSS feed

0.2.0

8 release files

This release

0.1.2 This release

8 release files

0.1.1

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