Skip to main content

Asynchronous MongoDB ORM for Tornado

Project description

======
Monguo
======

.. image:: https://github.com/shiyanhui/monguo/blob/master/doc/source/_static/monguo.jpg?raw=true
:width: 200px

:Info: Monguo is a full-featured, asynchronous MongoDB_ ORM with Motor_ dirver for Tornado_ applications.
:Author: Lime YH.Shi

.. _MongoDB: http://mongodb.org/
.. _Motor: https://github.com/mongodb/motor/
.. _Tornado: http://tornadoweb.org/


About
=====

Monguo is an asynchronous MongoDB ORM based on driver Motor_. The `source is on GitHub <https://github.com/shiyanhui/monguo>`_ and the docs are on `ReadTheDocs <http://monguo.readthedocs.org/en/latest/>`_.

Issues / Questions / Feedback
=============================

You can open an issue on `GitHub <https://github.com/shiyanhui/monguo/issues>`_ 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
========

.. code-block:: python

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:

.. code-block:: python

{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_.


.. _PyMongo: http://pypi.python.org/pypi/pymongo/
.. _MongoDB: http://mongodb.org/
.. _Tornado: http://tornadoweb.org/
.. _Motor: https://github.com/mongodb/motor/
.. _Greenlet: http://pypi.python.org/pypi/greenlet/
.. _ReadTheDocs: http://motor.readthedocs.org/
.. _sphinx: http://sphinx.pocoo.org/
.. _nose: http://somethingaboutorange.com/mrl/projects/nose/
.. _nose bug: https://github.com/nose-devs/nose/issues/556

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

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for monguo-0.1.tar.gz
Algorithm Hash digest
SHA256 c73c2a20b1a525fde16d464c123736e50dd4561c117b845ad7c4b9a25b08331c
MD5 7a5e133d543aa0abb8c70bd43a14ea73
BLAKE2b-256 a1c1eaaa949b751fbcb435f3af59b0f027499def9e213ad6fa0cd22b15431cc7

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