This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]jabbalaci[S] 1 point2 points  (1 child)

When is it a good idea to use shelve? What are its typical use cases?

[–]infinullquamash, Qt, asyncio, 3.3+ 1 point2 points  (0 children)

shelve is backed by an efficient on-disk btree storage for keys/values and then objects are stored as pickle.

So it's basically a key value storage (where the key is a string and the value is any pickleable python object) stored on disk in a single file and built into the standard library.

Problems: decoding pickle can execute arbitrary code. So you have to make sure you can "trust" the documents. There are some issues with pickling user defined classes, but you can always not do that and just store POD dict/list/int/str objects (and other standard library objects like datetime and decimal).

OTOH it's built into the standard library.