Transparent, drop-in compression for Python's pickle
Project description
zpickle
Transparent, drop-in compression for Python's pickle — smaller files, same API.
zpickle adds high-performance compression to your serialized Python objects using multiple state-of-the-art algorithms without changing how you work with pickle.
# Replace this:
import pickle
# With this:
import zpickle as pickle
# Everything else stays the same!
Features
- Drop-in replacement for the standard
picklemodule - Transparent compression — everything happens automatically
- Multiple algorithms — choose
zstd,brotli,zlib, orlzma(powered bycompress_utils) - Configure once, use everywhere — set global defaults for your entire app
- Smaller data — 2-10× smaller serialized data (depending on content and algorithm)
- Backward compatible — automatically reads both compressed and regular pickle data
- Complete API compatibility — all pickle functions work as expected
Installation
pip install zpickle
Quick Start
Basic Usage
import zpickle as pickle
# Serializing works exactly like pickle
data = {"complex": ["nested", {"data": "structure"}], "with": "lots of repetition"}
serialized = pickle.dumps(data) # Automatically compressed!
# Deserializing works the same way
restored = pickle.loads(serialized) # Automatically decompressed!
# File operations work too
with open("data.zpkl", "wb") as f:
pickle.dump(data, f)
with open("data.zpkl", "rb") as f:
restored = pickle.load(f)
Custom Configuration
import zpickle
# Configure global settings
zpickle.configure(algorithm='brotli', level=9) # Higher compression
# Or configure for a single operation
data = [1, 2, 3] * 1000
compressed = zpickle.dumps(data, algorithm='zstd', level=6)
Performance
Compression ratios versus standard pickle (higher is better):
| Data Type | zstd (default) | brotli | zlib | lzma |
|---|---|---|---|---|
| Dict/List | TBD | TBD | TBD | TBD |
| NumPy | TBD | TBD | TBD | TBD |
| Text | TBD | TBD | TBD | TBD |
| Binary | TBD | TBD | TBD | TBD |
Compression speed (MB/s, higher is better):
| Algorithm | Level 1 | Level 3 (default) | Level 9 |
|---|---|---|---|
zstd |
TBD | TBD | TBD |
brotli |
TBD | TBD | TBD |
zlib |
TBD | TBD | TBD |
lzma |
TBD | TBD | TBD |
Note: Performance varies by data characteristics. Run benchmarks on your specific data for accurate results.
How It Works
zpickle applies compression with minimal overhead:
- Objects are first serialized using standard pickle
- The pickle data is compressed using the selected algorithm
- A small header (7 bytes) is added to identify the format and algorithm
- When deserializing,
zpickleauto-detects the format and decompresses if needed
API Reference
zpickle maintains complete API compatibility with the standard pickle module:
Core Functions
dumps(obj, protocol=None, ..., algorithm=None, level=None)- Serialize and compress objectloads(data, ...)- Deserialize and decompress objectdump(obj, file, protocol=None, ..., algorithm=None, level=None)- Serialize to fileload(file, ...)- Deserialize from file
Configuration
configure(algorithm=None, level=None, min_size=None)- Set global defaultsget_config()- Get current configuration
Classes
Pickler(file, ...)- Subclass of pickle.Pickler with compressionUnpickler(file, ...)- Subclass of pickle.Unpickler with decompression
Alternatives
- Standard
pickle: No compression, but native to Python compressed_pickle: Similar concept, but less configurablejoblib: More focused on large NumPy arrays and parallel processingmsgpack,protobuf: Different serialization formats (not pickle-compatible)
License
This project is distributed under the MIT License. Read more >
Links
- GitHub Repository
- PyPI Package
- Issue Tracker
- compress-utils - The underlying compression library
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file zpickle-0.1.0.tar.gz.
File metadata
- Download URL: zpickle-0.1.0.tar.gz
- Upload date:
- Size: 20.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ef38bf7f58ec912917ae373665744ba8f4daf44f1d3af47ac1b250493f5e3d2d
|
|
| MD5 |
6d0fcafd4caf655152467daf72ece96c
|
|
| BLAKE2b-256 |
11abe90bed9e78b433f4b4543e99b33418569372393e8c2967c38c212321a8c3
|
Provenance
The following attestation bundles were made for zpickle-0.1.0.tar.gz:
Publisher:
test_and_package_wheel.yml on dupontcyborg/zpickle
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
zpickle-0.1.0.tar.gz -
Subject digest:
ef38bf7f58ec912917ae373665744ba8f4daf44f1d3af47ac1b250493f5e3d2d - Sigstore transparency entry: 182720411
- Sigstore integration time:
-
Permalink:
dupontcyborg/zpickle@0b72a957d71ce2521da711835cfcf775a0fac4ba -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/dupontcyborg
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
test_and_package_wheel.yml@0b72a957d71ce2521da711835cfcf775a0fac4ba -
Trigger Event:
push
-
Statement type:
File details
Details for the file zpickle-0.1.0-py3-none-any.whl.
File metadata
- Download URL: zpickle-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e567127a6aca1404c354331debcdb6e22988fb90981db9995a21c40c0a221ee3
|
|
| MD5 |
1838db0b8061f3b7bfc01aa7ba5b83a9
|
|
| BLAKE2b-256 |
9e248704e73a13c57ebe9f56981f68bfc09954445763e55056ba7a4290be8d3d
|
Provenance
The following attestation bundles were made for zpickle-0.1.0-py3-none-any.whl:
Publisher:
test_and_package_wheel.yml on dupontcyborg/zpickle
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
zpickle-0.1.0-py3-none-any.whl -
Subject digest:
e567127a6aca1404c354331debcdb6e22988fb90981db9995a21c40c0a221ee3 - Sigstore transparency entry: 182720413
- Sigstore integration time:
-
Permalink:
dupontcyborg/zpickle@0b72a957d71ce2521da711835cfcf775a0fac4ba -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/dupontcyborg
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
test_and_package_wheel.yml@0b72a957d71ce2521da711835cfcf775a0fac4ba -
Trigger Event:
push
-
Statement type: