skip to navigation
skip to content

mongodict 0.2.0

MongoDB-backed Python dict-like interface

Latest Version: 0.3.1

So you are storing some key-values in a dict but your data became huge than your memory or you want to persist it on the disk? Then mongodict is for you!

As it uses MongoDB to store the data, you get all cool MongoDB things, like shardings and replicas.

mongodict is supported under Python 2.7 and Python 3.2.


As simple as:

pip install mongodict


As it uses collections.MutableMapping as its base, you just need to change the line which creates your dict. For instace, just replace:

>>> my_dict = {}


>>> from mongodict import MongoDict
>>> my_dict = MongoDict(host='localhost', port=27017, database='my_dict',

and then use it like a normal dict:

>>> my_dict['python'] = 'rules'
>>> print my_dict['python']
>>> del my_dict['python']
>>> print my_dict['python']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "", line 23, in __getitem__
    raise KeyError
>>> my_dict['spam'] = 'eggs'
>>> my_dict['ham'] = 'damn'
>>> for key, value in my_dict.items():
...    print '{} = {}'.format(key, value)
spam = eggs
ham = damn

Enjoy! :-)


There is no kind of in-memory cache, so all key lookups will be translated in a MongoDB query but as MongoDB’s server put everything it can in memory, probably it’ll not be a problem (if your working set is always entire in memory).

Why not Redis?

Redis is “remote directory server” - it’s a great piece of software and can do the job if all your data fit on memory. By other side, MongoDB already have mature sharding and replica set features. So, if you need to store lots of key-value pairs that don’t fit on memory, mongodict can solve your problem.


mongodict does not have the same API other key-value software have (like memcached). Some features are missing to compete directly with these kind of software (by now we have only the dict-like behaviour), but I have plans to add it soon.


You can run the tests either with or without tox.

Without tox

This is the simplest approach: you’ll test only for one Python version. To do it, just execute:

mkvirtualenv --no-site-packages mongodict-without-tox
pip install -r requirements/develop.txt
make test

With tox

With tox you can test for more than one Python version (currently for 2.7 and 3.2). You just need to create a virtualenv, install and run it:

mkvirtualenv --no-site-packages tox-for-mongodict
pip install tox

tox will create one virtualenv for each Python version, install requirements and then run the tests for each of them.


This software was written and is maintained by Álvaro Justen (aka Turicas). Please contact me at alvarojusten at gmail dot com.


It’s licensed under GPL version 3.

File Type Py Version Uploaded on Size
mongodict-0.2.0.tar.gz (md5) Source 2012-08-06 15KB