Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Thunder is an object-relational mapper (ORM) for Python
Python Shell
branch: master




Thunder is an ORM for MongoDB built on top of the PyMongo driver.

It's inspired by Storm and reuses some APIs from mongoengine.


Thunder provides a Store class which provide apis for indexing and querying documents stored in MongoDB.

>>> from import Store

To create a simple store you can just provide the name of the database inside the mongo database:

>>> store = Store('mydb')

That's it, we now have a reference to store which can be used to insert and query objects.

First we need to define a document that can be inserted into a store:

>>> from storm.fields import ObjectIdField, StringField
>>> class Person(object):
...     id = ObjectIdField()
...     name = StringField()

All objects inserted into a store needs to at least have an ObjectIdField. There can only be one ObjectIdField per class.

To create a document you create the class normally:

>>> p = Person()
>>> = 'John Cleese'
>>> store.add(p)

Note that this doesn't actually index the document into the database, that's only done when an explicit flush is issued:

>>> store.find(Person).count()
>>> store.flush()

We can now query the store for the document:

>>> store.find(Person).count()
>>> for person in store.find(Person):
>>>     print person
<X object at 0x.....>
Something went wrong with that request. Please try again.