Recently, I needed a tool/UI to be able to restore data for a particular Python class from a Maya scene. The immediately obvious solutions were to simply store all the class properties as individual attributes, or store a JSON string containing the class data on a single string attribute. For simple classes or data, this is probably the way to go. However, I had a complex object with nested classes and some Maya API objects. Using these methods would have required writing the logic to properly write out the data and ultimately read it back in while properly instantiating all the necessary classes/objects.
Thankfully, Python gives us the pickle module (https://docs.python.org/2/library/pickle.html) for serializing and de-serializing data back into the proper Python objects/classes. Ultimately, I ended up using an extension of the pickle module, dill (https://github.com/uqfoundation/dill), as it supports more complex data types. In the process, I found out that Maya API objects were not handled by either pickle or dill. Fortunately, there's a way around that! http://www.ctrl-shift-kill.com/2015/09/30/picked-points-in-python/. With this all in place, I was able to pickle the data, and save it as a base64 encoded string to a single string attribute on my node. Upon re-opening the scene, I can unpickle that data and have my proper Python object hierarchy restored. I'm curious what approaches others have taken for similar situations.