What\'s the best way to store and retrieve a python dict in a database?
If the dict directly corresponds to a database table, then you should set up a table with a schema containing two columns - key
and value
. Then for each element of the dict, just insert it into the database, or update it if the key is already in place, etc.
Otherwise you could use pickle to serialize the dict to a string, and then you could just save the string to the DB. But in general I would not recommend this solution since you cannot query the serialized data.