[Answered ]-Django: Store a dictionary in a compressed binary format

2👍

âś…

I would encourage you to look into pickle field for object serialization in Python where the data is converted to a bytestream and stored.

The pickle module implements a fundamental, but powerful algorithm for serializing and de-serializing a Python object structure. “Pickling” is the process whereby a Python object hierarchy is converted into a byte stream, and “unpickling” is the inverse operation, whereby a byte stream is converted back into an object hierarchy. Pickling (and unpickling) is alternatively known as “serialization”, “marshalling,” 1 or “flattening”, however, to avoid confusion, the terms used here are “pickling” and “unpickling”.

To retrieve data, you would be “unpickling”.

More info here

There is also a django app called django-picklefield which is widely used.

The downside of your approach is, you have to take into consideration so many aspects. Also, use of eval is not recommended for security, etc..

Leave a comment