Coder Social home page Coder Social logo

mongodict's Introduction

mongodict - MongoDB-backed Python dict-like interface

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.

Installation

As simple as:

pip install mongodict

or:

easy_install mongodict

Usage

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 = {}

with:

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

and then use it like a normal dict:

>>> my_dict['python'] = 'rules'
>>> print my_dict['python']
'rules'
>>> del my_dict['python']
>>> print my_dict['python']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "mongodict.py", line 23, in __getitem__
    raise KeyError
KeyError

Enjoy! :-)

Note

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.

Note

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.

Author

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

Semantic Versioning

This software uses Semantic Versioning.

License

It's licensed under GPL version 3.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.