Metadata-Version: 2.4
Name: zlib-rust
Version: 0.6.8.post2
Requires-Dist: pytest>=8 ; extra == 'test'
Requires-Dist: hypothesis>=6 ; extra == 'test'
Requires-Dist: urllib3==2.8.0 ; extra == 'test'
Provides-Extra: test
License-File: LICENSE
License-File: licenses/cpython/LICENSE
License-File: licenses/heck-0.5.0/LICENSE-APACHE
License-File: licenses/heck-0.5.0/LICENSE-MIT
License-File: licenses/libc-0.2.191/LICENSE-APACHE
License-File: licenses/libc-0.2.191/LICENSE-MIT
License-File: licenses/once_cell-1.21.4/LICENSE-APACHE
License-File: licenses/once_cell-1.21.4/LICENSE-MIT
License-File: licenses/portable-atomic-1.15.0/LICENSE-APACHE
License-File: licenses/portable-atomic-1.15.0/LICENSE-MIT
License-File: licenses/proc-macro2-1.0.107/LICENSE-APACHE
License-File: licenses/proc-macro2-1.0.107/LICENSE-MIT
License-File: licenses/pyo3-0.30.1/LICENSE-APACHE
License-File: licenses/pyo3-0.30.1/LICENSE-MIT
License-File: licenses/pyo3-build-config-0.30.1/LICENSE-APACHE
License-File: licenses/pyo3-build-config-0.30.1/LICENSE-MIT
License-File: licenses/pyo3-ffi-0.30.1/LICENSE-APACHE
License-File: licenses/pyo3-ffi-0.30.1/LICENSE-MIT
License-File: licenses/pyo3-macros-0.30.1/LICENSE-APACHE
License-File: licenses/pyo3-macros-0.30.1/LICENSE-MIT
License-File: licenses/pyo3-macros-backend-0.30.1/LICENSE-APACHE
License-File: licenses/pyo3-macros-backend-0.30.1/LICENSE-MIT
License-File: licenses/quote-1.0.47/LICENSE-APACHE
License-File: licenses/quote-1.0.47/LICENSE-MIT
License-File: licenses/syn-3.0.9/LICENSE-APACHE
License-File: licenses/syn-3.0.9/LICENSE-MIT
License-File: licenses/target-lexicon-0.13.5/LICENSE
License-File: licenses/unicode-ident-1.0.27/LICENSE-APACHE
License-File: licenses/unicode-ident-1.0.27/LICENSE-MIT
License-File: licenses/unicode-ident-1.0.27/LICENSE-UNICODE
License-File: licenses/zlib-rs-0.5.3/LICENSE
License-File: licenses/zlib-rs-0.5.4/LICENSE
License-File: licenses/zlib-rs-0.5.5/LICENSE
License-File: licenses/zlib-rs-0.6.0/LICENSE
License-File: licenses/zlib-rs-0.6.1/LICENSE
License-File: licenses/zlib-rs-0.6.2/LICENSE
License-File: licenses/zlib-rs-0.6.3/LICENSE
License-File: licenses/zlib-rs-0.6.4/LICENSE
License-File: licenses/zlib-rs-0.6.5/LICENSE
License-File: licenses/zlib-rs-0.6.6/LICENSE
License-File: licenses/zlib-rs-0.6.7/LICENSE
License-File: licenses/zlib-rs-0.6.8/LICENSE
Summary: Python bindings for zlib-rs
Keywords: zlib,gzip,deflate,rust,compression
License-Expression: MIT
Requires-Python: >=3.11
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Issues, https://github.com/bugsink/zlib-rust/issues
Project-URL: Source, https://github.com/bugsink/zlib-rust

# zlib-rust

Python bindings for the Trifecta Tech Foundation's
[`zlib-rs`](https://github.com/trifectatechfoundation/zlib-rs), a fast Rust
implementation of zlib.

The foundation develops and maintains zlib-rs as part of its
[data compression initiative](https://trifectatech.org/initiatives/data-compression/).
The compression engine, its optimizations, and its Rust API are their work.
This package brings that work to Python, with a familiar interface and
installable wheels, independently of the library your Python distributor chose.

## How to use

```console
pip install zlib-rust
```

The public API follows Python's standard-library `zlib` module. The package
imports as `zlib_rust`, so switching your own code is explicit:

```python
import zlib_rust as zlib

compressed = zlib.compress(b"hello")
assert zlib.decompress(compressed) == b"hello"
```

Streaming compression and decompression use `compressobj()` and
`decompressobj()`. Raw DEFLATE, zlib, and gzip streams are supported through
the usual `wbits` parameter. Streaming decompression supports `max_length`
to bound the output of each call.

For gzip files, use the familiar `GzipFile` and `open()` interfaces:

```python
from zlib_rust.gzip import GzipFile

with GzipFile("events.gz", "wb") as stream:
    stream.write(b"hello\n")
```

The file-handling code comes from CPython's gzip module, using zlib-rs for
compression, decompression, and checksums. Both checksum-combine functions
are available on every supported Python version.

The binding forbids unsafe Rust and releases the GIL during codec operations.
Package versions follow the pinned zlib-rs crate version.

## Development

Install Rust 1.85 or newer and Python 3.11 or newer. Build a wheel with
`maturin build --release --locked`, install it into your development
environment, then run `pytest`.

This package was built with heavy use of LLMs. Its tests combine CPython's
zlib and gzip suites with interoperability tests against the standard-library
codec and tests for the Python binding. Imported tests retain their
[source references and documented adaptations](tests/upstream/cpython/SOURCE.md).

The Trifecta Tech Foundation's work makes this package possible. You can
[support the foundation](https://trifectatech.org/support/) to help sustain
zlib-rs and its other public-interest infrastructure projects.

## Alternatives (Python 3.16, conditions apply)

You can also use zlib-rs through Python's standard-library `zlib` module.
CPython 3.16 adds a
[`--with-zlib=zlib-rs` build option](https://docs.python.org/3.16/using/configure.html#cmdoption-with-zlib).
Install zlib-rs's C-compatible library (version 0.6.0 or newer), make it
discoverable through `pkg-config` as `libz_rs`, and compile CPython with that
option. A Python distributor can provide such a build too. Then ordinary
`import zlib`, including its use by `gzip` and `zipfile`, uses zlib-rs.

Python 3.16's final release is not scheduled until
[October 5, 2027](https://peps.python.org/pep-0826/). Even then, that choice
belongs to the interpreter build. Your operating system, container image, or
Python installer may choose another backend; installing an application
dependency cannot change it. This package lets you select zlib-rs for your own
code while using an existing Python installation, including older Python versions.

