On this page
pickle.PickleBuffer
Prev: pickle.loads | Up: pickle | Next: pickle.PickleError
Rel: pickle.dump, pickle.dumps, pickle.load, pickle.loads
Ref: docs.python.org โ pickle.PickleBuffer
Tags: #public #python3 #stdlib #pickle
Import
import pickle
from pickle import PickleBuffer
Signature & Overview
pickle.PickleBuffer(...)
Wrapper for potentially out-of-band buffers
Methods & Attributes
PickleBuffer.raw(self, /)โ Return a memoryview of the raw memory underlying this buffer.PickleBuffer.release(self, /)โ Release the underlying buffer exposed by the PickleBuffer object.
Usage
import pickle
buf = pickle.PickleBuffer(bytearray(b"zero-copy"))
buffers: list[pickle.PickleBuffer] = []
raw = pickle.dumps(buf, protocol=5, buffer_callback=buffers.append)
restored = pickle.loads(raw, buffers=buffers)
assert bytes(restored) == b"zero-copy"
Gotchas
- Requires
protocol=5: Enables out-of-band zero-copy transfer of large NumPy/bytearray buffers.
REPL Inspect
from pickle import PickleBuffer
help(PickleBuffer)
Linked from
Related notes
- tuts/python3/stdlib_module/pickle/dump Linked here; links to this page; shared tags: #pickle, #stdlib
- tuts/python3/stdlib_module/pickle/dumps Linked here; links to this page; shared tags: #pickle, #stdlib
- tuts/python3/stdlib_module/pickle/load Linked here; links to this page; shared tags: #pickle, #stdlib
- tuts/python3/stdlib_module/pickle/loads Linked here; links to this page; shared tags: #pickle, #stdlib
- tuts/python3/stdlib_module/pickle/PickleError Linked here; links to this page; shared tags: #pickle, #stdlib
- tuts/python3/stdlib_module/pickle Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/pickle/Pickler shared tags: #pickle, #stdlib
- tuts/python3/stdlib_module/pickle/PicklingError shared tags: #pickle, #stdlib
- tuts/python3/stdlib_module/pickle/Unpickler shared tags: #pickle, #stdlib
- tuts/python3/stdlib_module/pickle/UnpicklingError shared tags: #pickle, #stdlib