|
|
|
|
|
by sandGorgon
3833 days ago
|
|
can you talk about the usecase a little more. I'm trying to figure out why you would use marshmallow instead of pickling.. especially in context of building REST api. I use Flask and I am not sure where pickling comes in. I have built a desktop application in pyqt though and the multiprocessing modules need pickle-able data. |
|
However by using marshmallow for serializing, I found the resultant JSON output a much more manageable output format to 'reason with'. In my specific case where the lifetime of a python object could be extended over multiple sessions and pass through the runtime -> save -> db -> load -> runtime barrier, JSON was a hugely meaningful choice. The project used a graph of connected Python objects whose relations & states needed to be retained over time and memory barriers.
With a general HTTP REST API, I find that bundling all the related records of an entity in a single API call saves up the roundabout time for the client. In this case, instead of hand building a dict and then generating a json.dumps() I find using marshmallow a better choice - the declaration of the serializer itself, reflects the structure & the entity relations clearly.