Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Thunder is an object-relational mapper (ORM) for Python
Python Shell
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
thunder
.gitignore
LICENSE
MANIFEST.in
Makefile
NEWS
README.rst
ez_setup.py
requirements.txt
setup.cfg
setup.py
setup.sh

README.rst

Thunder

Presentation

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

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

Tutorial

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

>>> from storm.store 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()
>>> p.name = '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()
0
>>> store.flush()

We can now query the store for the document:

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