Skip to main content

sync/async MongoDB ODM, yes.

Project description

μMongo: sync/async ODM

https://img.shields.io/pypi/v/umongo.svg https://img.shields.io/travis/Scille/umongo.svg Documentation Status Code coverage

μMongo is a Python MongoDB ODM. It inception comes from two needs: the lack of async ODM and the difficulty to do document (un)serialization with existing ODMs.

>From this point, μMongo made a few design choices:

  • Stay close to the standards MongoDB driver to keep the same API when possible: use find({"field": "value"}) like usual but retrieve your data nicely OO wrapped !

  • Work with multiple drivers (PyMongo, TxMongo, motor_asyncio and mongomock for the moment)

  • Tight integration with Marshmallow serialization library to easily dump and load your data with the outside world

  • i18n integration to localize validation error messages

  • Free software: MIT license

  • Test with 90%+ coverage ;-)

Quick example

from datetime import datetime
from pymongo import MongoClient
from umongo import Instance, Document, fields, validate

db = MongoClient().test
instance = Instance(db)

@instance.register
class User(Document):
    email = fields.EmailField(required=True, unique=True)
    birthday = fields.DateTimeField(validate=validate.Range(min=datetime(1900, 1, 1)))
    friends = fields.ListField(fields.ReferenceField("User"))

    class Meta:
        collection = db.user

goku = User(email='goku@sayen.com', birthday=datetime(1984, 11, 20))
goku.commit()
vegeta = User(email='vegeta@over9000.com', friends=[goku])
vegeta.commit()

vegeta.friends
# <object umongo.data_objects.List([<object umongo.dal.pymongo.PyMongoReference(document=User, pk=ObjectId('5717568613adf27be6363f78'))>])>
vegeta.dump()
# {id': '570ddb311d41c89cabceeddc', 'email': 'vegeta@over9000.com', friends': ['570ddb2a1d41c89cabceeddb']}
User.find_one({"email": 'goku@sayen.com'})
# <object Document __main__.User({'id': ObjectId('570ddb2a1d41c89cabceeddb'), 'friends': <object umongo.data_objects.List([])>,
#                                 'email': 'goku@sayen.com', 'birthday': datetime.datetime(1984, 11, 20, 0, 0)})>

Get it now:

$ pip install umongo
$ pip install my-mongo-driver  # Note you have to manually install the mongodb driver

Or to get it along with the MongoDB driver you’re planing to use:

$ pip install umongo[pymongo]   # choose
$ pip install umongo[motor]     # one
$ pip install umongo[txmongo]   # of
$ pip install umongo[mongomock] # them ;-)

History

dev

0.13.0 (2017-01-02)

  • Fix deserialization error with nested EmbeddedDocuments (see #84, #67)

  • Add abstract and allow_inheritance options to EmbeddedDocument

  • Remove buggy as_marshmallow_schema’s parameter missing_accessor (see #73, #74)

0.12.0 (2016-11-11)

  • Replace Document.opts.children by offspring and fix grand child inheritance issue (see #66)

  • Fix dependancy since release of motor 1.0 with breaking API

0.11.0 (2016-11-02)

  • data_objects Dict and List inherit builtins dict and list

  • Document&EmbeddedDocument store fields passed during initialization as modified (see #50)

  • Required field inside embedded document are handled correctly (see #61)

  • Document support marshmallow’s pre/post processors

0.10.0 (2016-09-29)

  • Add pre/post update/insert/delete hooks (see #22)

  • Provide Umongo to Marshmallow schema/field conversion with schema.as_marshmallow_schema() and field.as_marshmallow_field() (see #34)

  • List and Dict inherit from collections’s UserList and UserDict instead of builtins types (needed due to metaprogramming conflict otherwise)

  • DeleteError and UpdateError returns the driver result object instead of the raw error dict (except for motor which only has raw error dict)

0.9.0 (2016-06-11)

  • Queries can now be expressed with the document’s fields name instead of the name in database

  • EmbeddedDocument also need to be registered by and instance before use

0.8.1 (2016-05-19)

  • Replace Document.created by is_created (see #14)

0.8.0 (2016-05-18)

  • Heavy rewrite of the project, lost of API breakage

  • Documents are now first defined as templates then implemented inside an Instance

  • DALs has been replaced by frameworks implementations of Builder

  • Fix __getitem__ for Pymongo.Cursor wrapper

  • Add conditions argument to Document.commit

  • Add count method to txmongo

0.7.8 (2016-4-28)

  • Fix setup.py style preventing release of version 0.7.7

0.7.7 (2016-4-28)

  • Fix await error with Reference.fetch

  • Pymongo is now only installed with extra flavours of umongo

0.7.6 (2016-4-28)

  • Use extras_require to install driver along with umongo

0.7.5 (2016-4-23)

  • Fixing await (Python >= 3.5) support for motor-asyncio

0.7.4 (2016-4-21)

  • Fix missing package in setup.py

0.7.3 (2016-4-21)

  • Fix setup.py style preventing from release

0.7.2 (2016-4-21)

  • Fix crash when generating indexes on EmbeddedDocument

0.7.1 (2016-4-21)

  • Fix setup.py not to install tests package

  • Pass status to Beta

0.7.0 (2016-4-21)

  • Add i18n support

  • Add MongoMock support

  • Documentation has been a lot extended

0.6.1 (2016-4-13)

  • Add <dal>_lazy_loader to configure Document’s lazy_collection

0.6.0 (2016-4-12)

  • Heavy improvements everywhere !

0.1.0 (2016-1-22)

  • First release on PyPI.

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

umongo-0.13.0.tar.gz (72.7 kB view details)

Uploaded Source

Built Distribution

umongo-0.13.0-py2.py3-none-any.whl (46.0 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file umongo-0.13.0.tar.gz.

File metadata

  • Download URL: umongo-0.13.0.tar.gz
  • Upload date:
  • Size: 72.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for umongo-0.13.0.tar.gz
Algorithm Hash digest
SHA256 cd57bf648abf47bc11fe677f0aed761c3d7d94ba589d11bd34af112d868a05e0
MD5 931c976fbcd9918f140605c8ac7c8e39
BLAKE2b-256 4a342b851a18aa1fbbe26843a37d2470434416e8950775e686b35a95d31e1dc5

See more details on using hashes here.

File details

Details for the file umongo-0.13.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for umongo-0.13.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ba2cf6f8535d4cec5a3aa1184dfeb9ca0c910f9d99e19b96cbddf912d781fe78
MD5 ac89d09612a8fef061136e17bea4b063
BLAKE2b-256 2eba434d44cf3b60e43344e192f15f151faa3451143aab4c153db698b7083bbe

See more details on using hashes here.

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