## 3.17.1 Restrictions

- The choice of which database package will be used (such as `dbm`, `gdbm` or `bsddb`) depends on which interface is available. Therefore it is not safe to open the database directly using `dbm`. The database is also (unfortunately) subject to the limitations of `dbm`, if it is used -- this means that (the pickled representation of) the objects stored in the database should be fairly small, and in rare cases key collisions may cause the database to refuse updates.

- Depending on the implementation, closing a persistent dictionary may or may not be necessary to flush changes to disk. The `__del__` method of the `Shelf` class calls the `close` method, so the programmer generally need not do this explicitly.

- The `shelve` module does not support concurrent read/write access to shelved objects. (Multiple simultaneous read accesses are safe.) When a program has a shelf open for writing, no other program should have it open for reading or writing. Unix file locking can be used to solve this, but this differs across Unix versions and requires knowledge about the database implementation used.

class `Shelf`( | dict[, protocol=None[, writeback=False[, binary=None]]])

  A subclass of `UserDict.DictMixin` which stores pickled values in the dict object.

  By default, version 0 pickles are used to serialize values. The version of the pickle protocol can be specified with the protocol parameter. See the `pickle` documentation for a discussion of the pickle protocols. Changed in version 2.3: The protocol parameter was added. The binary parameter is deprecated and provided for backwards compatibility only.

  If the writeback parameter is `True`, the object will hold a cache of all entries accessed and write them back to the dict at sync and close times. This allows natural operations on mutable entries, but can consume much more memory and make sync and close take a long time.

class `BsdDbShelf`( | dict[, protocol=None[, writeback=False[, binary=None]]])

  A subclass of `Shelf` which exposes `first`, `next`, `previous`, `last` and `set_location` which are available in the `bsddb` module but not in other database modules. The dict object passed to the constructor must support those methods. This is generally accomplished by calling one of `bsddb.hashopen`, `bsddb.btopen` or `bsddb.rnopen`. The optional protocol, writeback, and binary parameters have the same interpretation as for the `Shelf` class.

class `DbfilenameShelf`( | filename[, flag='c'[, protocol=None[, writeback=False[, binary=None]]]])

  A subclass of `Shelf` which accepts a filename instead of a dict-like object. The underlying file will be opened using `anydbm.open`. By default, the file will be created and opened for both read and write. The optional flag parameter has the same interpretation as for the `open` function. The optional protocol, writeback, and binary parameters have the same interpretation as for the `Shelf` class.