joblib
provide a replacement for pickle to work efficiently on arbitrary Python objects containing large data, in particular large numpy arrays
As of Python 3.8 and numpy 1.16, pickle protocol 5 introduced in PEP 574 supports efficient serialization and de-serialization for large data buffers
joblib.load() should therefore never be used to load objects from an untrusted source
Serialize with File Stream
import joblib
l = list(range(10))
f = open('temp.joblib', 'wb')
# serialization
joblib.dump(l, f)
f.close()
f = open('temp.joblib', 'rb')
# deserialization
print(joblib.load(f))
f.close()
Serialize with File Name
l = list(range(10))
# serialization
joblib.dump(l, 'temp.pkl')
# deserialization
joblib.load('temp.pkl')
Compress
# support 'z', ‘gzip’, ‘bz2’, ‘lzma’ and ‘xz’:
l = list(range(10))
# serialization
joblib.dump(l, 'temp.z')
# deserialization
joblib.load('temp.z')
Reference