Reading BinPickle Files¶
Reading an object from a BinPickle file is done with
from binpickle import load obj = load('file.bpk')
Load an object from a BinPickle file.
file (str or pathlib.Path) – The file to load.
For full control of the deserialization process, and in particular to support
memory-mapped object contents (e.g. for shared memory use), use
If you open the BinPickle file in direct mode (the
binpickle.BinPickleFile.__init__()), then the contents of buffers
in the object (e.g. NumPy arrays or Pandas columns) will be directly backed by
a read-only memory-mapped region from the BinPickle file. This has two
Multiple processes with the same file open in direct mode will (usually) share buffer memory. This is one of BinPickle’s particular benefits: an easy way to load large array data, such as the learned parameters of many SciKit-style machine learning models, in multiple processes with minimal duplication.
binpickle.BinPickleFileobject cannot be closed until all objects referencing its memory have been destroyed.
binpickle.BinPickleFile.close()will throw an exception if it is closed prematurely.
- class binpickle.BinPickleFile(filename, *, direct=False)¶
Class representing a binpickle file in memory.
filename (str or pathlib.Path) – The name of the file to load.
direct (bool) – If
True, returned objects zero-copy when possible, but cannot outlast the
False, they are copied from the file and do not need to be freed before
Load the object from the binpickle file.
Verify binpickle data structure validity. If the file is invalid, returns a list of errors.
Fatal index errors will result in a failure to open the file, so things such as invalid msgpack formats in the index won’t be detected here. This method checks buffer checksums, offset overlaps, and such.
Close the BinPickle file. If the file is in direct mode, all retrieved objects and associated views must first be deleted.