sync/async MongoDB ODM
Project description
μ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:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file umongo-4.0.0.tar.gz.
File metadata
- Download URL: umongo-4.0.0.tar.gz
- Upload date:
- Size: 175.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c9e9d0795924397658f5b013cb0bac96b8e2f562358e40ba10de1143bbe79be
|
|
| MD5 |
c244ecb5f07e8dd0180ac03f88e48ff0
|
|
| BLAKE2b-256 |
e6afe012442938077251dda607f4653c4999a9aeb1bcd43889127b23e3d0135e
|
Provenance
The following attestation bundles were made for umongo-4.0.0.tar.gz:
Publisher:
build-release.yml on Scille/umongo
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
umongo-4.0.0.tar.gz -
Subject digest:
6c9e9d0795924397658f5b013cb0bac96b8e2f562358e40ba10de1143bbe79be - Sigstore transparency entry: 1006502057
- Sigstore integration time:
-
Permalink:
Scille/umongo@aa72595312699b772d234103889b4e7e8330f659 -
Branch / Tag:
refs/tags/4.0.0 - Owner: https://github.com/Scille
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-release.yml@aa72595312699b772d234103889b4e7e8330f659 -
Trigger Event:
push
-
Statement type:
File details
Details for the file umongo-4.0.0-py3-none-any.whl.
File metadata
- Download URL: umongo-4.0.0-py3-none-any.whl
- Upload date:
- Size: 45.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
34a1ea6ef90fc669d3db657cfd43772da1e7c28539424e250b637d5c734fda4b
|
|
| MD5 |
f2e62bb047f51ac5c23774b5d010cbbf
|
|
| BLAKE2b-256 |
aa87e1723a240bc5785abb25bbd2ec3096710bdd98197b0f29243af7d2d0db94
|
Provenance
The following attestation bundles were made for umongo-4.0.0-py3-none-any.whl:
Publisher:
build-release.yml on Scille/umongo
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
umongo-4.0.0-py3-none-any.whl -
Subject digest:
34a1ea6ef90fc669d3db657cfd43772da1e7c28539424e250b637d5c734fda4b - Sigstore transparency entry: 1006502058
- Sigstore integration time:
-
Permalink:
Scille/umongo@aa72595312699b772d234103889b4e7e8330f659 -
Branch / Tag:
refs/tags/4.0.0 - Owner: https://github.com/Scille
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-release.yml@aa72595312699b772d234103889b4e7e8330f659 -
Trigger Event:
push
-
Statement type: