Today, the MongoDB Python Team is pleased to announce the release of a brand-new project: PyMODM!
PyMODM is a Pythonic, object-oriented interface for working with MongoDB. It's an ORM-like library whose goal is to make defining and validating document structures and relationships easy.
Here's a quick example:
from pymodm import connect, MongoModel, fields
# Connect to MongoDB.
connect('mongodb://localhost:27017/myDatabase')
# Define an "Image" model, which gets its own collection in "myDatabase".
class Image(MongoModel):
# Store images in GridFS.
upload = fields.ImageField()
# Define an "Author" model, also with its own collection.
class Author(MongoModel):
name = fields.CharField(max_length=100)
# Reference to a document in the "image" collection, by id.
icon = fields.ReferenceField(Image)
# Create an Image and an Author and save them to MongoDB.
with open('icon.png') as author_image:
image = Image(author_image).save()
Author(name='Ira Talot', icon=image).save()
# Load the image file for our author from GridFS.
retrieved_file = Author.objects.first().image.upload
This is only a taste. You can also read the full documentation (https://pymodm.readthedocs.io/en/latest/) or visit the project's Github (https://github.com/mongodb/pymodm/) to learn more.
This is the very first release of the project, and we're very excited to know what you think. You can grab a copy of PyMODM like this:
pip install pymodm
To get image support with Pillow (https://pypi.python.org/pypi/Pillow), install it like this:
pip install pymodm[images]
PyMODM, like other drivers projects, has its bug tracker located on the MongoDB Jira. To file a bug or request a feature, please open a new PYMODM ticket here: https://jira.mongodb.org/browse/PYMODM
This project also has its own Gitter channel (https://gitter.im/mongodb/pymodm), where you can ask questions and chat with other community members.
Please try it out! We're excited to hear from you, and we look forward to many future releases.
- The MongoDB Python Team