I am trying to cache the metadata of images that are downloaded from the internet using a dictionary (I'm not interested in the images themselves). The id (int) of the image is the key and a custom class representing the metadata is the value.
I want to write this dictionary to a file before program exit so I don't have to download the information again on the next startup, but I have some trouble serializing it.
So far I tried:
- Serializing it to JSON using the builtin json module -> JSON doesn't support numbers as keys, serializing complex types seems quite complicated and unreliable
- Serializing it to XML using various snippets that I found online -> complex type as the value generates a lot of trouble and most solutions seem to only work for specific use cases
How can I serialize a dictionary (int, custom_class)? The serialized format should be human readable and must be deserializable.
I'm using Python 3.4 and external dependencies would be ok, as long as I can install them using pip.