μMongo: sync/async ODM¶
μMongo is a Python MongoDB ODM. Its 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
import datetime as dt
from pymongo import MongoClient
from umongo import Document, fields, validate
from umongo.frameworks import PyMongoInstance
db = MongoClient().test
instance = PyMongoInstance(db)
@instance.register
class User(Document):
email = fields.EmailField(required=True, unique=True)
birthday = fields.DateTimeField(
validate=validate.Range(min=dt.datetime(1900, 1, 1))
)
friends = fields.ListField(fields.ReferenceField("User"))
class Meta:
collection_name = "user"
# Make sure that unique indexes are created
User.ensure_indexes()
goku = User(email="goku@sayen.com", birthday=dt.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 # This installs umongo with pymongo
$ pip install my-mongo-driver # Other MongoDB drivers must be installed manually
Or to get it along with the MongoDB driver you’re planing to use:
$ pip install umongo[motor]
$ pip install umongo[txmongo]
$ pip install umongo[mongomock]
Support umongo¶
If you’d like to support the future of the project, please consider contributing to Marshmallow’s Open Collective:
Contents:¶
- User guide
- Migrating
- API Reference
- Contributing
- Credits
- Changelog
- 4.0.0 (2026-03-01)
- 4.0.0b4 (2025-10-07)
- 4.0.0b3 (2025-10-02)
- 4.0.0b2 (2025-09-22)
- 4.0.0b1 (2025-09-21)
- 3.1.0 (2021-12-23)
- 3.0.1 (2021-10-16)
- 3.0.0 (2021-01-11)
- 3.0.0b14 (2020-12-08)
- 3.0.0b13 (2020-11-23)
- 3.0.0b12 (2020-11-16)
- 3.0.0b11 (2020-11-06)
- 3.0.0b10 (2020-10-12)
- 3.0.0b9 (2020-10-05)
- 3.0.0b8 (2020-07-22)
- 3.0.0b7 (2020-05-08)
- 3.0.0b6 (2020-05-04)
- 3.0.0b5 (2020-04-30)
- 3.0.0b4 (2020-04-27)
- 3.0.0b3 (2020-04-26)
- 3.0.0b2 (2020-04-18)
- 3.0.0b1 (2020-03-29)
- 2.3.0 (2020-09-06)
- 2.2.0 (2019-12-18)
- 2.1.1 (2019-10-04)
- 2.1.0 (2019-06-19)
- 2.0.5 (2019-06-13)
- 2.0.4 (2019-05-28)
- 2.0.3 (2019-04-10)
- 2.0.2 (2019-04-10)
- 2.0.1 (2019-03-25)
- 2.0.0 (2019-03-18)
- 1.2.0 (2019-02-08)
- 1.1.0 (2019-01-14)
- 1.0.0 (2018-11-29)
- 0.15.0 (2017-08-15)
- 0.14.0 (2017-03-03)
- 0.13.0 (2017-01-02)
- 0.12.0 (2016-11-11)
- 0.11.0 (2016-11-02)
- 0.10.0 (2016-09-29)
- 0.9.0 (2016-06-11)
- 0.8.1 (2016-05-19)
- 0.8.0 (2016-05-18)
- 0.7.8 (2016-4-28)
- 0.7.7 (2016-4-28)
- 0.7.6 (2016-4-28)
- 0.7.5 (2016-4-23)
- 0.7.4 (2016-4-21)
- 0.7.3 (2016-4-21)
- 0.7.2 (2016-4-21)
- 0.7.1 (2016-4-21)
- 0.7.0 (2016-4-21)
- 0.6.1 (2016-4-13)
- 0.6.0 (2016-4-12)
- 0.1.0 (2016-1-22)
Indices and tables¶
Misc¶
This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.