Skip to content

Add pickle support

Julien Fausty requested to merge julien.fausty/vtk:add-pickle-support into master

The Python pickle module (https://docs.python.org/3/library/pickle.html) is often used to serialize python objects to disk for later loading. This MR introduces the capability to use the python pickle module to both pickle and unpickle vtkDataObjects python wrapped objects. The serialization of the data object uses the marshaling capabilities of vtkCommunicator behind the scenes.

In order to use this new feature in python, you must first run:

import vtkmodules.util.pickle_support

Once you have imported the module the pickling of data objects is completely transparent. Here is a code snippet:

from vtkmodules.vtkFiltersSources import vtkSphereSource
import vtk.util.pickle_support
import pickle

sphereSrc = vtk.vtkSphereSource()
sphereSrc.Update()

pickled = pickle.dumps(sphereSrc.GetOutput())

unpickled = pickle.loads(pickled)

print(unpickled)
Edited by Julien Fausty

Merge request reports