Notice: This project was built entirely with AI assistance and is an experimental proof of concept. It is not intended for production use. Use at your own risk.
zlib-rs-python
A high-performance, memory-safe Python binding for the zlib-rs Rust crate. Up to 22x faster than CPython's built-in zlib module.
Features
- High Performance -- Up to 22x faster compression and 17x faster checksums compared to CPython's built-in zlib (see benchmarks).
- Memory Safe -- Built on top of
zlib-rs, a memory-safe, pure-Rust implementation of the zlib compression algorithm. - Drop-in Compatible -- Follows the standard Python
zlibAPI. Swap imports and go. - Cross-Platform -- Builds and runs on Linux, macOS, and Windows with no C dependencies.
- Zero C Dependencies -- No system zlib headers or C compiler required. Everything is compiled from Rust source.
Installation
From PyPI
pip install zlib-rs
From Source
pip install maturin
git clone https://github.com/farhaanaliii/zlib-rs-python.git
cd zlib-rs-python
maturin develop --release
Quick Start
import zlib_rs as zlib
# One-shot compression
data = b"Hello, zlib-rs!" * 1000
compressed = zlib.compress(data)
original = zlib.decompress(compressed)
assert data == original
# Streaming compression
compressor = zlib.compressobj(level=6)
compressed = compressor.compress(data)
compressed += compressor.flush()
decompressor = zlib.decompressobj()
result = decompressor.decompress(compressed)
assert data == result
# Checksums
checksum_adler = zlib.adler32(data)
checksum_crc = zlib.crc32(data)
Drop-in Replacement
To use zlib-rs globally in an existing project without changing every import:
import sys
import zlib_rs
sys.modules["zlib"] = zlib_rs
# Now any library importing 'zlib' will use 'zlib-rs' instead
import zlib
compressed = zlib.compress(b"transparent replacement")
API Reference
| Function / Class | Description |
|---|---|
compress(data, level=-1) |
One-shot compression. Returns compressed bytes. |
decompress(data, wbits=15, bufsize=16384) |
One-shot decompression. Returns original bytes. |
compressobj(level, method, wbits, ...) |
Create a streaming compression object. |
decompressobj(wbits, zdict) |
Create a streaming decompression object. |
adler32(data, value=1) |
Compute Adler-32 checksum. |
crc32(data, value=0) |
Compute CRC-32 checksum. |
All standard zlib constants are available: Z_BEST_COMPRESSION, Z_BEST_SPEED, Z_DEFAULT_COMPRESSION, Z_DEFAULT_STRATEGY, Z_DEFLATED, Z_FINISH, Z_NO_FLUSH, Z_SYNC_FLUSH, MAX_WBITS, DEF_MEM_LEVEL, etc.
Benchmarks
All benchmarks measured on Windows, Python 3.12, with release optimizations
(lto = "fat", codegen-units = 1, target-cpu=native).
One-Shot Compression
| Data Size | Level | CPython zlib | zlib-rs | Speedup |
|---|---|---|---|---|
| 1 KB | 1 | 57.2 us | 46.3 us | 1.2x faster |
| 1 KB | 6 | 62.6 us | 20.0 us | 3.1x faster |
| 64 KB | 1 | 155.6 us | 63.2 us | 2.5x faster |
| 64 KB | 6 | 398.1 us | 86.3 us | 4.6x faster |
| 1 MB | 6 | 6.45 ms | 401.4 us | 16.1x faster |
| 10 MB | 6 | 94.60 ms | 4.22 ms | 22.4x faster |
One-Shot Decompression
| Data Size | Level | CPython zlib | zlib-rs | Speedup |
|---|---|---|---|---|
| 1 KB | 1 | 4.4 us | 2.3 us | 1.9x faster |
| 64 KB | 9 | 50.5 us | 15.0 us | 3.4x faster |
| 1 MB | 6 | 1.18 ms | 664.0 us | 1.8x faster |
| 10 MB | 1 | 11.99 ms | 5.86 ms | 2.0x faster |
Checksums
| Operation | Data Size | CPython zlib | zlib-rs | Speedup |
|---|---|---|---|---|
| adler32 | 64 KB | 21.0 us | 2.0 us | 10.5x faster |
| crc32 | 64 KB | 41.9 us | 3.2 us | 13.1x faster |
| adler32 | 1 MB | 364.6 us | 33.1 us | 11.0x faster |
| crc32 | 1 MB | 814.8 us | 48.3 us | 16.9x faster |
Running Benchmarks
maturin develop --release
python benchmarks/bench_zlib.py
Development
Prerequisites
Setup
git clone https://github.com/farhaanaliii/zlib-rs-python.git
cd zlib-rs-python
python -m venv .venv
# Linux / macOS
source .venv/bin/activate
# Windows (PowerShell)
.\.venv\Scripts\Activate.ps1
pip install maturin pytest
Build
Debug build (fast compile, slow runtime):
maturin develop
Release build (slow compile, fast runtime -- recommended for benchmarks):
maturin develop --release
Test
pytest tests/ -v
Dev Scripts
Platform-specific dev scripts are provided in the scripts/ directory:
| Script | Description |
|---|---|
scripts/dev.ps1 |
Windows: build, test, and benchmark |
scripts/dev.sh |
Linux/macOS: build, test, and benchmark |
scripts/release.ps1 |
Windows: bump version, tag, and push release |
scripts/release.sh |
Linux/macOS: bump version, tag, and push release |
Usage:
# Windows (PowerShell)
.\scripts\dev.ps1 build # Build release
.\scripts\dev.ps1 test # Run tests
.\scripts\dev.ps1 bench # Run benchmarks
.\scripts\dev.ps1 all # Build + test + bench
# Linux / macOS
./scripts/dev.sh build
./scripts/dev.sh test
./scripts/dev.sh bench
./scripts/dev.sh all
Project Structure
zlib-rs-python/
src/
lib.rs # Rust source -- PyO3 bindings to zlib-rs
python/
zlib_rs/
__init__.py # Python package entry point
tests/
test_compatibility.py # Basic cross-compat tests
test_compress.py # One-shot compress/decompress
test_streaming.py # Streaming operations
test_checksums.py # adler32/crc32
test_edge_cases.py # Edge cases, constants, errors
benchmarks/
bench_zlib.py # Performance comparison vs CPython zlib
scripts/
dev.ps1 # Windows dev script
dev.sh # Linux/macOS dev script
release.ps1 # Windows release script
release.sh # Linux/macOS release script
.github/
workflows/
CI.yml # Test + lint on push/PR
release.yml # Cross-platform build + PyPI publish on tag
Cargo.toml # Rust dependencies and release profile
pyproject.toml # Python package metadata (PyPI)
LICENSE
README.md
Releasing
Releases are automated via GitHub Actions. To create a new release:
# Windows
.\scripts\release.ps1 0.2.0
# Linux / macOS
./scripts/release.sh 0.2.0
This will:
- Update version in
Cargo.tomland__init__.py - Build and test locally
- Commit, create a
v0.2.0tag, and push to GitHub - GitHub Actions then builds cross-platform wheels (Linux x86_64/aarch64, Windows x86_64, macOS x86_64/arm64)
- Tests wheels on all platforms
- Publishes to PyPI
- Creates a GitHub Release with all wheel assets
Contributing
Contributions are welcome. Please see CONTRIBUTING.md for guidelines.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Acknowledgements
Metadata
Release files for zlib-rs 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| zlib_rs-0.1.2.tar.gz | 22.8 kB | Details |
Built distributions (wheels)
Total release size: 3.4 MB
Release files / zlib_rs-0.1.2.tar.gz
| Download URL | zlib_rs-0.1.2.tar.gz |
|---|---|
| Size | 22.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1e6214c5f2a83a2751c9716d9da8672745825f62a3d89669ac73a1e7ea3efba0
|
|
BLAKE2b-256 checksum How to use checksums |
10d537a2db5c2bae8b900dc52527a3a1bb740731741cfe680ec816d10ce282de
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Feb 19, 2026.
Transparency logRelease files / zlib_rs-0.1.2-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | zlib_rs-0.1.2-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 296.2 kB |
| Tags | Linux glibc 2.17+ x86-64 PyPy 3.11 PyPy 3.11 7.3 |
|
SHA-256 checksum How to use checksums |
f9bda5812249662fec9d6f44a4c2e121feb4262a5287bd73e0cd2666ad594661
|
|
BLAKE2b-256 checksum How to use checksums |
5875c032dd0b38a5cc5ccfa9878b87c9a70a6e016ebdee9d5cb7faa217a96c24
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Feb 19, 2026.
Transparency logRelease files / zlib_rs-0.1.2-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | zlib_rs-0.1.2-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 294.7 kB |
| Tags | CPython 3.14 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
b6fb5ccda44794cdf3c4ad23fa4da820c6535a5822c3f3f8e92f115d2805fa68
|
|
BLAKE2b-256 checksum How to use checksums |
f42f1a1009843ce207a40bb3e12df2c17b1909e9e2bda414da0ba1c3080682ce
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Feb 19, 2026.
Transparency logRelease files / zlib_rs-0.1.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | zlib_rs-0.1.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 294.8 kB |
| Tags | CPython 3.13 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
0d18eabc33c978bb7c21bb4369e1dc854a44185b494fb081b4a7d2c617a3524e
|
|
BLAKE2b-256 checksum How to use checksums |
30fec97bc4688167af0be463601da828c5fc90203883dd5149e347637bfe22f5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Feb 19, 2026.
Transparency logRelease files / zlib_rs-0.1.2-cp312-cp312-win_amd64.whl
| Download URL | zlib_rs-0.1.2-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 202.4 kB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
4e0a3f54001f077fb3014078ab0fe190569ecf7baa14f3bddc4b8995dc146a43
|
|
BLAKE2b-256 checksum How to use checksums |
6deeb410d039532c059e9d10216cd5a6a18dd9cd4e482101a38f731959f04b42
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Feb 19, 2026.
Transparency logRelease files / zlib_rs-0.1.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | zlib_rs-0.1.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 295.0 kB |
| Tags | CPython 3.12 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
a0d4e33a380b08cd375ac933b5a56dcfa149e1fbdc8934717a51742d58b0348c
|
|
BLAKE2b-256 checksum How to use checksums |
ad7f2117730fa6c172c457fa07add5bf9f1fdaeb7bf69ec8efda51289e20e382
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Feb 19, 2026.
Transparency logRelease files / zlib_rs-0.1.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | zlib_rs-0.1.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 280.9 kB |
| Tags | CPython 3.12 Linux glibc 2.17+ ARM64 |
|
SHA-256 checksum How to use checksums |
154760c38600ed1ebf2aeee5794ad8d3805a08db47d0cb4d7f4c69053ac8d015
|
|
BLAKE2b-256 checksum How to use checksums |
43d44fea55ed3cb18637246d8c7433c3283af8a12da17758cace3f7e46e3c269
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Feb 19, 2026.
Transparency logRelease files / zlib_rs-0.1.2-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | zlib_rs-0.1.2-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 254.8 kB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
de1203affe28dcb3bd714570fcd022cf67b7d6ab6b90095999311813062aca56
|
|
BLAKE2b-256 checksum How to use checksums |
b8975849217e4865ff05af5d6d7f1a275797cc3d7043577be17a24e7512e9db3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Feb 19, 2026.
Transparency logRelease files / zlib_rs-0.1.2-cp312-cp312-macosx_10_12_x86_64.whl
| Download URL | zlib_rs-0.1.2-cp312-cp312-macosx_10_12_x86_64.whl |
|---|---|
| Size | 282.9 kB |
| Tags | CPython 3.12 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
a002a69e6820aa2550240a0f21859f55fa771123082f093423abea74fe520822
|
|
BLAKE2b-256 checksum How to use checksums |
1877e452a3856b67c3a8768a43c2ba7476ec3e9ee131391b092703d2d2a0b18a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Feb 19, 2026.
Transparency logRelease files / zlib_rs-0.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | zlib_rs-0.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 295.2 kB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
8405369a4b1482ca1adeb51d8f7be922ac75e81c016eb85625278c93226d477d
|
|
BLAKE2b-256 checksum How to use checksums |
a03daefc5a7b330d91e1308b5d0b59bc90b658d2f089fd79c94ec4e230794422
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Feb 19, 2026.
Transparency logRelease files / zlib_rs-0.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | zlib_rs-0.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 295.5 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
8189fa4c32be03e08dc9a8407aee79df91e8f29ff2cb5bc826cd4e6a1d6dedda
|
|
BLAKE2b-256 checksum How to use checksums |
87d23068ab0abb9102b672a490009f09fbeb4a0f945ec6c5df347d7ef73ad865
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Feb 19, 2026.
Transparency logRelease files / zlib_rs-0.1.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | zlib_rs-0.1.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 297.9 kB |
| Tags | CPython 3.9 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
0587e35653692ffa1d696526ccaf41a337960c62fc2286c0a4bfc2b0af2b2bcc
|
|
BLAKE2b-256 checksum How to use checksums |
6cb8ba12fd96b42f72f4dc0002cc4f2014f0e40e2181e9eaf2513f873233c489
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Feb 19, 2026.
Transparency logRelease files / zlib_rs-0.1.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | zlib_rs-0.1.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 298.1 kB |
| Tags | CPython 3.8 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
0daf266f1f2744c0ece24b7ae9f4e699da58fcf9e9dfd0970c7bc99284277a86
|
|
BLAKE2b-256 checksum How to use checksums |
f15e6f72892d63fb805bcda7501fd7a85c811965c404fc099f494105b53b7378
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Feb 19, 2026.
Transparency log