Search code examples
pythonmongodbshelvenosql

NoSQL database in python: What are some of the things that "shelve" can't do?


The Python Standard Library has a NoSQL database, shelve, that seems quite adequate. Yet other NoSQL (mongoDB) databases remain very popular.

If I choose shelve over the more popular alternatives, what are the main features that I will be forgoing?


Solution

  • shelve is just a very simple key-value store where each assignment is also written to a DB. It's interface is basically idential to that of a python dict, and that's it. It has no support for concurrent read/write access; multiple readers can access safely access a shelve DB, but if any of them could be writing, it's not safe. It's performance is not particularly good, since it's uses pickle to serialize the objects it stores, which isn't very fast.

    Fully featured NoSQL DBs like MongoDB offers many more features, like replication, auto-sharding, support for indexes, more advanced querying, atomic writes, etc. Performance and scalability are going to be better, too.

    That said, if you're just trying to access your DB from a single application, don't need to store very much data, don't need any kind of advanced querying, and don't need the best possible performance, then you'll probably be ok with shelve. Otherwise, you probably want something more robust.