Package: persistentdicts
persistentdictsdict-like interfaces for various databasesKey differences with competing projectsIf you search on pypi, you will find a few competing projects: pdicts,
durabledicts, etc. The key differences between persistentdicts and those
are:Implementations of persistentdicts do not keep a local cache
dictionary: changes are immediately written to database. Iterators
are also proceeding directly on the database. It allows to interact
with datasets that would not fit in RAM otherwise.The test suite is significantly bigger than in all the other
implementation I have seen. When relevant, tests have been backported
from the CPython test suite of dict.Serialization is done in json rather than using pickle.GotchasYou can’t modify a value of the dictionary in place. For example:>>> import persistentdicts

>>> d = persistentdicts.sqlitedict.SqliteDict()
>>> d["a"] = []
>>> d["a"].append(1)

>>> d["a"] # with a normal dict, you would get [1]
[]That is becaused["a"]returns a copy of the database entry for the
key"a", and not a reference to a python object. Modifying this copy
(withappend) does not affect the database itself.To circumvent this, you should do:>>> import persistentdicts

>>> d = persistentdicts.sqlitedict.SqliteDict()
>>> d["a"] = []
>>> d["a"] = d["a"] + [1]

>>> d["a"]
[1]Similarly,setdefaultwill not work as expected since it does not
return a reference to the stored value, but a copy of this value.>>> import persistentdicts

>>> d = persistentdicts.sqlitedict.SqliteDict()
>>> d.setdefault("a", []).append(1)

>>> d["a"]
[]Databases supported so farDone:kyotocabinetsqlitecassandraPlanned:leveldbredismemcachedblightcloudYou can request new formats on thebug tracker.Short documentationpersistentdicts.sqlitedict.SqliteDictpersistentdicts.sqlitedict.SqliteDict(path=":memory:", table="dict", isolation_level="DEFERRED", *args, **kwargs)pathis the path to the file where you wish to store the datadictis the table to use in this fileisolation_levelis the isolation level used for all transactions.
See thesqlite
documentationfor more details.the remaining arguments*args, **kwargsare used to fill the
dictionary (like a normaldict)persistentdicts.kyotocabinetdict.KyotoCabinetDictpersistentdicts.kyotocabinetdict.KyotoCabinetDict(path, *args, **kwargs)pathis the path to the file where you wish to store the data.
The file extension matters and will determine which format is going
to be used internally (must be one of .kch, .kct, .kcd, .kcf or
.kcx). See thekyotocabinet
documentationfor more details.the remaining arguments*args, **kwargsare used to fill the
dictionary (like a normaldict)persistentdicts.cassandradict.CassandraDictpersistentdicts.cassandradict.CassandraDict(contact_points=("127.0.0.1",), port=9042, keyspace="dict", table="dict", *args, **kwargs)contact_pointsis an initial list of ip addresses which are part of
the Cassandra cluster. The Cassandra driver will automatically discover
the rest of the cluster.portis the port on which Cassandra runs.keyspaceis the keyspace used to store the data. This keyspace will
be deleted if the method.delete()is called on the CassandraDicttableis the name of the table used to store the data.the remaining arguments*args, **kwargsare used to fill the
dictionary (like a normaldict)