Storing Python dictionaries
⚡TLDR
Instantly store a Python dict using json for persistence:
Here json.dump() stores data, and json.load() retrieves it in a .json format, intelligible by all programming languages.
Quick and dirty with Pickle
Don't mind about cross-language readability or security? pickle is your friend:
Note: Use 'wb' and 'rb' modes for binary writings and readings respectively with pickle.
Pretty JSON for Homo-sapiens
When readability is important, you can make JSON pretty:
Considering alternatives: ujson and klepto
For ultra-fast operations, swap json with ujson:
For dictionary-like archiving to a file, directory, or database, check klepto:
Hashes to ashes, bits to bytes
When files are too large or complex, consider other serialization/deserialization methods:
dill: stores almost anything in Python, perfect for complex objects.ujson: ultra-fast encoding and decoding, when time is money.klepto: dictionary-like archiving to files, directories, or databases, when order and structure are your thing.
Remember: Good encoding and decoding practices can save you from many headaches.
Linked
Linked
Was this article helpful?