Skip to main content

Asynchronous MongoDB ORM for Tornado

Project description

https://github.com/shiyanhui/monguo/blob/master/doc/source/_static/monguo.jpg?raw=true
Info:

Monguo is a full-featured, asynchronous MongoDB ORM with Motor dirver for Tornado applications.

Author:

Lime YH.Shi

About

Monguo is an asynchronous MongoDB ORM based on driver Motor. The source is on GitHub and the docs are on ReadTheDocs.

Issues / Questions / Feedback

You can open an issue on GitHub or email me directly at shiyanhui66@gmail.com if you have any question or feedback.

Installation

$ pip install monguo

Dependencies

Monguo works in all the environments officially supported by Tornado and Motor. It requires:

  • Unix, including Mac OS X. Microsoft Windows is not officially supported.

  • PyMongo

  • Greenlet

  • Tornado 3.0+ (temporarily)

  • Motor 0.1+ (temporarily)

  • CPython 2.6, 2.7, 3.2, or 3.3

  • PyPy 2.0 (greenlets were very slow in earlier PyPy versions)

Additional dependencies are:

  • (to generate documentation) sphinx

Examples

class BookDocument(EmbeddedDocument):
    name  = StringField(required=True)
    pages = IntegerField(required=True)


class SkillDocument(EmbeddedDocument):
    name = StringField(required=True)


class PetDocument(Document):
    name = StringField(required=True)
    say  = StringField()

    meta = {
        'collection': 'pet'
    }


class UserDocument(Document):
    name   = StringField(required=True, unique=True)
    sex    = StringField(required=True, default='male')
    age    = IntegerField(required=True)
    skills = ListField(DictField(SkillDocument), required=True)
    book   = EmbeddedDocumentField(BookDocument, required=True)
    pet    = ReferenceField(PetDocument)

    meta = {
        'collection': 'user'
    }

    def insert_user():
        user = {
            'name': 'Lime',
            'age': 100,
            'skills': [{'name': 'python'}, {'name': 'Web Programming'}],
            'book': {'name': 'I am a bad guy', 'pages': '888'},
        }
        user_id = yield UserDocument.save(user)
        raise gen.Return(user_id)


@gen.coroutine
def main():
    Connection.connect('test')

    pet_id = yield PetDocument.insert({'name': 'dog'})
    pet = yield PetDocument.find_one({'_id': ObjectId(pet_id)})
    print pet

    user_id = yield UserDocument.insert_user()
    user = yield UserDocument.find_one({'name': 'Lime'})
    print user

    dbref = DBRef(PetDocument.meta['collection'], ObjectId(pet_id))
    yield UserDocument.update({'name': 'Lime'}, {'$set': {'pet': dbref}})
    user = yield UserDocument.find_one({'name': 'Lime'})
    print user

IOLoop.instance().run_sync(main)

The result:

{u'_id': ObjectId('526208447379180fcb0dec0a'), u'name': u'dog'}

{u'name': u'Lime', u'skills': [{u'name': u'python'}, {u'name': u'Web Programming'}], u'age': 100L, u'sex': u'male', u'book': {u'name': u'I am a bad guy', u'pages': 888L}, u'_id': ObjectId('526208447379180fcb0dec0b')}

{u'name': u'Lime', u'pet': DBRef(u'pet', ObjectId('526208447379180fcb0dec0a')), u'age': 100L, u'sex': u'male', u'skills': [{u'name': u'python'}, {u'name': u'Web Programming'}], u'book': {u'name': u'I am a bad guy', u'pages': 888L}, u'_id': ObjectId('526208447379180fcb0dec0b')}

Documentation

You will need sphinx installed to generate the documentation. Documentation can be generated by running python setup.py doc. Generated documentation can be found in doc/build/html/. You can read the current docs at ReadTheDocs.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

monguo-0.1.1.tar.gz (12.0 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page