Skip to main content

PyMODM is a generic ODM on top of PyMongo.

Project description

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

A generic ODM around PyMongo, the MongoDB Python driver. 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.

Why PyMODM?

PyMODM is a “core” ODM, meaning that it provides simple, extensible functionality that can be leveraged by other libraries to target platforms like Django. At the same time, PyMODM is powerful enough to be used for developing applications on its own. Because MongoDB engineers are involved in developing and maintaining the project, PyMODM will also be quick to adopt new MongoDB features.

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 Community Forums.

Bugs / Feature Requests

Think you’ve found a bug? Want to see a new feature in PyMODM? Please 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 pymongo import TEXT
from pymongo.operations import IndexModel
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.CharField(max_length=20))
    # These Comment objects will be stored inside each Post document in the
    # database.
    comments = fields.EmbeddedDocumentListField('Comment')

    class Meta:
        # Text index on content can be used for text search.
        indexes = [IndexModel([('content', TEXT)])]

# 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.4.3.tar.gz (55.4 kB view details)

Uploaded Source

Built Distributions

pymodm-0.4.3-py3-none-any.whl (48.2 kB view details)

Uploaded Python 3

pymodm-0.4.3-py2-none-any.whl (48.2 kB view details)

Uploaded Python 2

File details

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

File metadata

  • Download URL: pymodm-0.4.3.tar.gz
  • Upload date:
  • Size: 55.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.5

File hashes

Hashes for pymodm-0.4.3.tar.gz
Algorithm Hash digest
SHA256 b9fc352dabca1c10bc9342167ab322ce2898b68a79c42e19f0baa7d5b7578ea1
MD5 e30cd1871de72e00fade686cb1dcf880
BLAKE2b-256 d068d2001233b684b8d32e988188c85def43a2ef6a4b1e8b074942c0c0120aff

See more details on using hashes here.

File details

Details for the file pymodm-0.4.3-py3-none-any.whl.

File metadata

  • Download URL: pymodm-0.4.3-py3-none-any.whl
  • Upload date:
  • Size: 48.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.5

File hashes

Hashes for pymodm-0.4.3-py3-none-any.whl
Algorithm Hash digest
SHA256 697b23d93695fdbaccc995912aecb203d1f1d8f8bff7ad90a9180f6a2986d084
MD5 afe2f4ed48a451b66a259dd5959dcc18
BLAKE2b-256 1550d250e457eeb4bd49a9a0d26bbb5918a15689dac3b5b0d594beec11e30090

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pymodm-0.4.3-py2-none-any.whl
  • Upload date:
  • Size: 48.2 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.5

File hashes

Hashes for pymodm-0.4.3-py2-none-any.whl
Algorithm Hash digest
SHA256 98e790bb457a7faf4e0aca71ff8a13d584eb6d9075db98202c8f1ce334675e55
MD5 cdf1a4f6214865f8aaf6012eb0b4d50f
BLAKE2b-256 30d226765629b9d984fc10a0f5abf2b3551c847c691d4f57b375205c06996dc4

See more details on using hashes here.

Supported by

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