Skip to content

A liteweight Object Document Manager for MongoDB and Python.

Notifications You must be signed in to change notification settings

Zaharid/mongotraits

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mongotraits

A liteweight simple Object Document Manager to connect Python objects to MongoDB, similar to mongoengine

Features

  • Based on IPython Traitlets.
  • User interface in IPython Notebook for creating and adding objects via the widgetrepr package.
  • Objects with the same id are always the same python object.
  • References are special TraitType subclasses that implement a dereference and a ref methods.
  • References to embedded objects are possible.
  • Arbitrary objects can be saved: They either implement a savedict and to_classdict methods, are represented unchanged if they are of the right type (SAME_TYPES) or they are pickled.
  • Container traits are handled correctly.

The drawbacks I can think of are:

  • The performance has not been taken into account at all.
  • No fancy query meta language (but pymongo is easy enough to use).

Dependencies

Install

Download the package and run python setup.py install.

Example

import datetime

import mongotraits
from IPython.utils import traitlets

mongotraits.connect('test')
    

class BlogPost(mongotraits.Document):
    author = traitlets.Unicode()
    title = traitlets.Unicode()
    content = traitlets.Unicode()
    references = traitlets.List(mongotraits.Reference(__name__ + '.BlogPost'))
    

my_post = BlogPost(author = 'Zah', title = "First Post", content = "Mongotraits is nice and easy")
other_post = BlogPost(author = 'Zah', title = "Second Post", content = "Another post", references = [my_post,])
my_post.save()
other_post.save()

#The object is already saved in MongoDB
del other_post

#Can find using 
loaded_post= BlogPost.find_one({'title':"Second Post"})

#Same id always corresponds to the same Python object.
assert(loaded_post.references[0] is my_post)

Known bugs

Circular references do not work properly at the moment.

About

A liteweight Object Document Manager for MongoDB and Python.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages