Skip to main content

PyMODM is a generic ODM on top of PyMongo.

This project has been archived.

The maintainers of this project have marked this project as archived. No new releases are expected.

Project description

View build status Join the chat at https://gitter.im/mongodb/pymodm

A generic ODM around PyMongo, the MongoDB Python driver. Its goal is to provide an easy, object-oriented interface to MongoDB documents. PyMODM works on Python 2.7 as well as Python 3.3 and up. To learn more, you can browse the official documentation or take a look at some examples.

Support / Feedback

For issues with, questions about, or feedback for PyMODM, please look into our support channels. Please do not email any of the PyMODM developers directly with issues or questions - you’re more likely to get an answer on the mongodb-user list on Google Groups.

Bugs / Feature Requests

Think you’ve found a bug? Want to see a new feature in PyMODM? open a case in our issue management tool, JIRA:

Bug reports in JIRA for all driver projects (e.g. PYMODM, PYTHON, JAVA) and the Core Server (i.e. SERVER) project are public.

How To Ask For Help

Please include all of the following information when opening an issue:

  • Detailed steps to reproduce the problem, including full traceback, if possible.

  • The exact python version used, with patch level:

    $ python -c "import sys; print(sys.version)"
  • The exact version of PyMODM used, with patch level:

    $ python -c "import pymodm; print(pymodm.version)"
  • The PyMongo version used, with patch level:

    $ python -c "import pymongo; print(pymongo.version)"
  • The operating system and version (e.g. Windows 7, OSX 10.8, …)

  • Web framework or asynchronous network library used, if any, with version (e.g. Django 1.7, mod_wsgi 4.3.0, gevent 1.0.1, Tornado 4.0.2, …)

Security Vulnerabilities

If you’ve identified a security vulnerability in a driver or any other MongoDB project, please report it according to the instructions here.

Example

Here’s a basic example of how to define some models and connect them to MongoDB:

from pymodm import connect, fields, MongoModel, EmbeddedMongoModel


# Connect to MongoDB first. PyMODM supports all URI options supported by
# PyMongo. Make sure also to specify a database in the connection string:
connect('mongodb://localhost:27017/myApp')


# Now let's define some Models.
class User(MongoModel):
    # Use 'email' as the '_id' field in MongoDB.
    email = fields.EmailField(primary_key=True)
    fname = fields.CharField()
    lname = fields.CharField()


class BlogPost(MongoModel):
    # This field references the User model above.
    # It's stored as a bson.objectid.ObjectId in MongoDB.
    author = fields.ReferenceField(User)
    title = fields.CharField(max_length=100)
    content = fields.CharField()
    tags = fields.ListField(fields.StringField(max_length=20))
    # These Comment objects will be stored inside each Post document in the
    # database.
    comments = fields.EmbeddedDocumentListField('Comment')


# This is an "embedded" model and will be stored as a sub-document.
class Comment(EmbeddedMongoModel):
    author = fields.ReferenceField(User)
    body = fields.CharField()
    vote_score = fields.IntegerField(min_value=0)


# Start the blog.
# We need to save these objects before referencing them later.
han_solo = User('mongoblogger@reallycoolmongostuff.com', 'Han', 'Solo').save()
chewbacca = User(
    'someoneelse@reallycoolmongostuff.com', 'Chewbacca', 'Thomas').save()


post = BlogPost(
    # Since this is a ReferenceField, we had to save han_solo first.
    author=han_solo,
    title="Five Crazy Health Foods Jabba Eats.",
    content="...",
    tags=['alien health', 'slideshow', 'jabba', 'huts'],
    comments=[
        Comment(author=chewbacca, body='Rrrrrrrrrrrrrrrr!', vote_score=42)
    ]
).save()


# Find objects using familiar MongoDB-style syntax.
slideshows = BlogPost.objects.raw({'tags': 'slideshow'})

# Only retrieve the 'title' field.
slideshow_titles = slideshows.only('title')

# u'Five Crazy Health Foods Jabba Eats.'
print(slideshow_titles.first().title)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pymodm-0.1.0.tar.gz (45.3 kB view details)

Uploaded Source

Built Distribution

pymodm-0.1.0-py2-none-any.whl (47.1 kB view details)

Uploaded Python 2

File details

Details for the file pymodm-0.1.0.tar.gz.

File metadata

  • Download URL: pymodm-0.1.0.tar.gz
  • Upload date:
  • Size: 45.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pymodm-0.1.0.tar.gz
Algorithm Hash digest
SHA256 87afeb4518bb73451d60cf9be8c6f5dc3c7aaa83cfa047f4f26b84231223a649
MD5 de94ec8d62cc82d0a85e1487cb495901
BLAKE2b-256 234fca766bd36ee8e33743141f5d02a3774de6bd0839a0955dcc82e891cb889c

See more details on using hashes here.

File details

Details for the file pymodm-0.1.0-py2-none-any.whl.

File metadata

File hashes

Hashes for pymodm-0.1.0-py2-none-any.whl
Algorithm Hash digest
SHA256 ef5394f5f0a014f810c1d20c0917b0d366138118152de5dc80166cc546704ab8
MD5 40c4137a47a56668cb469a2d1eda2742
BLAKE2b-256 25ec826556475816b0a7099a1752ec24967f09f0b15aa327b736d1c0f6fc07c5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page