Skip to main content

zpickle

Build Status GitHub Release License

Python Versions PyPI Version PyPI Downloads

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 pickle module
  • Transparent compression — everything happens automatically
  • Multiple algorithms — choose zstd, brotli, zlib, lzma, bzip2, lz4, snappy, or gzip (powered by compress_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

Each algorithm is benchmarked at compress-utils level 3 (zpickle's default) on two datasets (complex Python objects, JSON).

Compression ratios versus standard pickle (higher is better):

Bar graph showing data compression ratios versus pickle

Serialization speed (MB/s, higher is better):

Bar graph showing data compression speeds versus pickle

Note: Performance varies by data characteristics. Run benchmarks on your specific data for accurate results.

To run your own benchmarks, you can use:

python -m benchmarks.benchmark

How It Works

zpickle applies compression with minimal overhead:

  1. Objects are first serialized using standard pickle
  2. The pickle data is compressed using the selected algorithm
  3. A small header (8 bytes) is added to identify the format and algorithm
  4. When deserializing, zpickle auto-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 object
  • loads(data, ...) - Deserialize and decompress object
  • dump(obj, file, protocol=None, ..., algorithm=None, level=None) - Serialize to file
  • load(file, ...) - Deserialize from file

Configuration

  • configure(algorithm=None, level=None, min_size=None) - Set global defaults
  • get_config() - Get current configuration

Classes

  • Pickler(file, ...) - Subclass of pickle.Pickler with compression
  • Unpickler(file, ...) - Subclass of pickle.Unpickler with decompression

Alternatives

  • Standard pickle: No compression, but native to Python
  • compressed_pickle: Similar concept, but less configurable
  • joblib: More focused on large NumPy arrays and parallel processing
  • msgpack, protobuf: Different serialization formats (not pickle-compatible)

License

MIT © Nicolas Dupont — Read more >

Metadata

Release files for zpickle 1.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for zpickle 1.4.0
File Size Uploaded
zpickle-1.4.0.tar.gz 744.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for zpickle 1.4.0
File Interpreter ABI Platform
zpickle-1.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 759.1 kB

Release files / zpickle-1.4.0.tar.gz

Download URL zpickle-1.4.0.tar.gz
Size 744.8 kB
Tags Source
SHA-256 checksum
How to use checksums
500db124381acc9264f3e9127af7fbb6197677917657b37505c9b36b815cae81
BLAKE2b-256 checksum
How to use checksums
c7397f0b626414078028e2d187c7afb63deb8c2a2e9d8536fb199e083b40b43e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.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 Jul 23, 2026.

Transparency log

Release files / zpickle-1.4.0-py3-none-any.whl

Download URL zpickle-1.4.0-py3-none-any.whl
Size 14.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
022620b3411e4bb50f9141478b99f11741234038ea51f21bfc94888222ce1662
BLAKE2b-256 checksum
How to use checksums
3e3c1962d9971bd2e4f346d99c862b9d4c3de2a288809ba297b83da04f34b932
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.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 Jul 23, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.4.0 This release

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.1.0

2 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