GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - Scille/umongo: sync/async MongoDB ODM, yes.

BranchesTags
Open more actions menu

Latest commit

 

History

912 Commits
912 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
docs
docs
 
 
examples
examples
 
 
src/umongo
src/umongo
 
 
tests
tests
 
 
.coveragerc
.coveragerc
 
 
.editorconfig
.editorconfig
 
 
.gitignore
.gitignore
 
 
.pre-commit-config.yaml
.pre-commit-config.yaml
 
 
.readthedocs.yml
.readthedocs.yml
 
 
AUTHORS.rst
AUTHORS.rst
 
 
CHANGELOG.rst
CHANGELOG.rst
 
 
CONTRIBUTING.rst
CONTRIBUTING.rst
 
 
LICENSE
LICENSE
 
 
README.rst
README.rst
 
 
RELEASING.rst
RELEASING.rst
 
 
messages.pot
messages.pot
 
 
pyproject.toml
pyproject.toml
 
 
tox.ini
tox.ini
 
 

Repository files navigation

μMongo: sync/async ODM

Latest version Build status pre-commit.ci status Documentation Coverage

μ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="[email protected]", birthday=dt.datetime(1984, 11, 20))
goku.commit()
vegeta = User(email="[email protected]", 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': '[email protected]', friends': ['570ddb2a1d41c89cabceeddb']}
User.find_one({"email": "[email protected]"})
# <object Document __main__.User({'id': ObjectId('570ddb2a1d41c89cabceeddb'), 'friends': <object umongo.data_objects.List([])>,
#                                 'email': '[email protected]', '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:

Donate to our collective

About

sync/async MongoDB ODM, yes.

Topics

asynciomongodbodmpython3twisted

Resources

Readme
MIT license

Contributing

Contributing
Activity
Custom properties

Stars

446 stars

Watchers

10 watching

Forks

68 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.