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

https://travis-ci.org/shiyanhui/monguo.png https://pypip.in/v/monguo/badge.png https://pypip.in/d/monguo/badge.png

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 git+https://github.com/mongodb/motor.git
$ 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.

  • Tornado 3.0+ (temporarily)

  • Motor 0.1+ (temporarily)

Additional dependencies are:

  • (to generate documentation) sphinx

Examples

class UserDocument(Document):
    name  = StringField(required=True, unique=True, max_length=20)
    email = EmailField(required=True)
    age   = IntegerField()
    sex   = StringField(required=True, default='male',
                                       candidate=['male', 'female'])
    meta = {
        'collection': 'user'
    }

    def get_user_list(skip=10, limit=5):
        result = yield UserDocument.find().to_list(limit)
        raise gen.Return(result)


class CommentDocument(EmbeddedDocument):
    commentor = ReferenceField(UserDocument, required=True)
    contents  = StringField(required=True, max_length=200)


class PostDocument(Document):
    author       = ReferenceField(UserDocument, required=True)
    publish_time = DateTimeField(required=True)
    title        = StringField(required=True, max_length=100)
    contents     = StringField(max_length=5000)
    comments     = ListField(EmbeddedDocumentField(CommentDocument))

    meta = {
        'collection': 'post'
    }

# connect to database
Connection.connect('test')

# insert
bob_id = yield UserDocument.insert({
    'name': 'Bob',
    'email': 'bob@gmail.com',
    'age': 19
})

alice_id = yield UserDocument.insert({
    'name': 'Alice',
    'email': 'alice@gmail.com',
    'sex': 'female',
    'age': 18
})

post_id = yield PostDocument.insert({
    'author': DBRef(UserDocument.meta['collection'], bob_id),
    'publish_time': datetime.now(),
    'title': 'title',
})

# update
comment = {
    'commentor': DBRef(UserDocument.meta['collection'], alice_id),
    'contents': 'I am comments.'
}
yield PostDocument.update({'_id': post_id},
                          {'$push': {'comments': comment}})

# query
user = yield UserDocument.find_one({'name': 'Bob'})
posts = yield PostDocument.find().to_list(5)

# higher API
user_list = yield UserDocument.get_user_list()

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.2.tar.gz (14.5 kB view details)

Uploaded Source

File details

Details for the file monguo-0.2.tar.gz.

File metadata

  • Download URL: monguo-0.2.tar.gz
  • Upload date:
  • Size: 14.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for monguo-0.2.tar.gz
Algorithm Hash digest
SHA256 2477c57ac55c5d3253eedde7d2d1c9b7325b7a64feee2d78d0121e7adaf452ac
MD5 1a395a4ca6cfba70508363568f9a6ec6
BLAKE2b-256 1d5a90f22e546f6ebecd073974d814e8dee4f6ac8bc3297110d911767615dfd4

See more details on using hashes here.

Supported by

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