An ORM-like Pymongo extension that adds json schema validation, index management and intermediate data manipulators
Project description
Pymongoext
Pymongoext is an ORM-like Pymongo extension that adds json schema validation, index management and intermediate data manipulators. Pymongoext simplifies working with MongoDB, while maintaining a syntax very identical to Pymongo.
Documentation is available at https://pymongoext.readthedocs.io
The code is hosted on Github https://github.com/musyoka-morris/pymongoext
Supported MongoDB & Python Versions
Pymongoext uses JSON Schema for validation and thus we only support MongoDB v3.6+.
Pymongoext supports python v3+. Support for python v2.7 is currently under consideration.
Installation
We recommend the use of virtualenv and of pip. You can then use pip install -U pymongoext.
You may also have setuptools and thus you can use easy_install -U pymongoext. Another option is pipenv. You can then use pipenv install pymongoext to both create the virtual environment and install the package.
Alternatively, you can download the source from GitHub and run python setup.py install.
Examples
Some simple examples of what pymongoext code looks like:
from datetime import datetime
from pymongo import MongoClient, IndexModel
from pymongoext import *
class User(Model):
@classmethod
def db(cls):
return MongoClient()['my_database_name']
__schema__ = DictField(dict(
email=StringField(required=True),
name=StringField(required=True),
yob=IntField(minimum=1900, maximum=2019)
))
__indexes__ = [IndexModel('email', unique=True), 'name']
class AgeManipulator(Manipulator):
def transform_outgoing(self, doc, model):
doc['age'] = datetime.now().year - doc['yob']
return doc
# Create a user
>>> User.insert_one({'email': 'jane@gmail.com', 'name': 'Jane Doe', 'yob': 1990})
# Fetch one user
>>> user = User.find_one()
# Print the users age
>>> print(user['age'])
Contributing
We welcome contributions! See the Contribution guidelines
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
Hashes for pymongoext-2.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b56704088d0a2c514d5c5320ef4817f97b11127e19c408db7f453737e32b908 |
|
MD5 | af5051e147e7c5d6dee7dc45c42c87bd |
|
BLAKE2b-256 | dcdd477599dea68580523142217937e03d08473256ee1ad9e8dc84a0aaa07e22 |