compress-pickle

2.1.0 · active · verified Wed Apr 15

compress-pickle is a Python library (version 2.1.0) that thinly wraps the standard `pickle` package with various standard compression libraries (gzip, bz2, lzma, zipfile, and optionally lz4). It provides an interface similar to `pickle.dump`, `pickle.load`, `pickle.dumps`, and `pickle.loads` to seamlessly serialize and deserialize Python objects to disk or file-like objects in a compressed manner. The library has an infrequent release cadence, with its last major update in September 2021.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `compress_pickle.dump` to serialize and compress a Python dictionary to a file, and `compress_pickle.load` to decompress and deserialize it back. The compression method (gzip in this case) is automatically inferred from the file extension '.pkl.gz'.

from compress_pickle import dump, load
import os

data = {'key': 'value', 'numbers': [1, 2, 3]}
filename = 'my_compressed_data.pkl.gz'

# Dump (serialize and compress) the data
dump(data, filename)
print(f"Data saved to {filename} with inferred gzip compression.")

# Load (decompress and deserialize) the data
loaded_data = load(filename)
print(f"Data loaded successfully: {loaded_data}")

# Clean up the created file
os.remove(filename)

view raw JSON →