Registry / serialization / pgzip
library0.4.0pypypi✓ verified 85d ago

pgzip is a Python library that provides a multi-threading implementation of the standard `gzip` module. It aims to be a drop-in replacement, offering significant performance improvements for compression and decompression of large files by leveraging parallel processing. It achieves this by utilizing block indexing within the gzip file's `FEXTRA` field, ensuring compatibility with standard gzip tools. The library is actively maintained, with a recent major release (0.4.0) indicating ongoing development and support for newer Python versions.

pip install pgzip
INSTALL
IMPORT
SIG · PGZIP
P
pgzip
serializationpythonv0.4.0
Install
1.5s avg
Import
36ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.4.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.037s · 17.9MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.5s · import 0.036s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

pgzip
import pgzip
The library typically replaces direct usage of the standard `gzip` module. Its `open`, `compress`, and `decompress` functions mirror `gzip`'s API.
open
with pgzip.open('file.gz', 'wb') as f: ...
Used for file-like operations, accepting `thread` and `blocksize` parameters for parallelization.
compress
compressed_data = pgzip.compress(data)
Compresses bytes in memory, also accepts `thread` and `compresslevel`.
decompress
decompressed_data = pgzip.decompress(compressed_data)
Decompresses bytes in memory, also accepts `thread`.

This quickstart demonstrates how to use `pgzip.open` for compressing and decompressing data to/from a file, as well as `pgzip.compress` and `pgzip.decompress` for in-memory byte manipulation. It utilizes `tempfile` for a runnable, clean example. Note the use of `thread` and `blocksize` parameters for parallelization.

import pgzip import os import tempfile # Create some dummy data original_data = b"This is a test string that will be compressed using pgzip. " * 1000 with tempfile.TemporaryDirectory() as tmpdir: filepath_gz = os.path.join(tmpdir, "test_data.txt.gz") # 1. Compress data to a file using 4 threads and 1MB blocks print(f"Compressing data to {filepath_gz}...") with pgzip.open(filepath_gz, "wb", thread=4, blocksize=2**20) as f_out: f_out.write(original_data) print(f"Compressed file size: {os.path.getsize(filepath_gz)} bytes") # 2. Decompress data from the file using 4 threads print(f"Decompressing data from {filepath_gz}...") with pgzip.open(filepath_gz, "rb", thread=4) as f_in: decompressed_data_file = f_in.read() assert original_data == decompressed_data_file print("File compression and decompression successful!") # 3. In-memory compression and decompression using default threads print("\nPerforming in-memory compression/decompression...") compressed_bytes = pgzip.compress(original_data, compresslevel=6) decompressed_bytes = pgzip.decompress(compressed_bytes) assert original_data == decompressed_bytes print(f"In-memory compression/decompression successful! Compressed size: {len(compressed_bytes)} bytes")
Debug
Known issues
breakingpgzip v0.4.0 dropped support for Python 3.7, 3.8, and 3.9. It now officially supports Python versions 3.10 through 3.14.
fix
Users on Python < 3.10 must upgrade their Python environment to 3.10 or newer, or downgrade `pgzip` to a compatible version (e.g., `pgzip==0.3.5`).
affects: >=0.4.0
gotchaWhile `pgzip` is designed for performance, its parallel processing overhead can make it slower than the standard `gzip` module for files or data streams smaller than approximately 1MB.
fix
For very small files, consider using Python's built-in `gzip` module. For larger files, `pgzip` offers significant speedups. Optimize `blocksize` and `thread` parameters for your specific workload and data size.
affects: All
gotchapgzip only replaces specific functions and the `GzipFile` class from the standard `gzip` module (`open()`, `compress()`, `decompress()`). Other `gzip` features, such as `seek()` and `tell()`, might not be fully supported or tested.
fix
Review the official `pgzip` documentation for a precise list of supported features. If you rely on advanced `gzip` functionalities, test `pgzip` thoroughly or consider alternative strategies.
affects: All
Errors
Common errors & fixes
AttributeError: '_io.BufferedReader' object has no attribute '_read_exact'
This error was common in `pgzip` versions prior to 0.3.5 when used with Python 3.11, due to internal changes in Python's `gzip` module that `pgzip` relied upon.
fix
Upgrade `pgzip` to version 0.3.5 or newer: `pip install --upgrade pgzip`.
RuntimeError: Python version 3.x.y is not supported by pgzip 0.4.0. Requires >=3.10
Attempting to use `pgzip` version 0.4.0 or later with an unsupported Python version (e.g., Python 3.7, 3.8, or 3.9).
fix
Upgrade your Python environment to version 3.10 or newer. Alternatively, if upgrading Python is not feasible, downgrade `pgzip` to a compatible version, such as `pip install pgzip==0.3.5`.
Upgrade
Version history
0.4.0latest on PyPI · released Dec 23, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
pgzip — pip install pgzip · libregistry