Skip to main content
Info:

MongoEngine is an ORM-like layer on top of PyMongo.

Repository:

https://github.com/MongoEngine/mongoengine

Author:

Harry Marr (http://github.com/hmarr)

Maintainer:

Bastien Gerard (http://github.com/bagerard)

https://travis-ci.org/MongoEngine/mongoengine.svg?branch=master https://coveralls.io/repos/github/MongoEngine/mongoengine/badge.svg?branch=master https://img.shields.io/badge/code%20style-black-000000.svg https://pepy.tech/badge/mongoengine/month https://img.shields.io/pypi/v/mongoengine.svg https://readthedocs.org/projects/mongoengine-odm/badge/?version=latest

About

MongoEngine is a Python Object-Document Mapper for working with MongoDB. Documentation is available at https://mongoengine-odm.readthedocs.io - there is currently a tutorial, a user guide, and an API reference.

Supported MongoDB Versions

MongoEngine is currently tested against MongoDB v4.4, v5.0, v6.0 and v7.0. Future versions should be supported as well, but aren’t actively tested at the moment. Make sure to open an issue or submit a pull request if you experience any problems with a more recent MongoDB versions.

Installation

We recommend the use of virtualenv and of pip. You can then use python -m pip install -U mongoengine. You may also have setuptools and thus you can use easy_install -U mongoengine. Another option is pipenv. You can then use pipenv install mongoengine to both create the virtual environment and install the package. Otherwise, you can download the source from GitHub and run python setup.py install.

The support for Python2 was dropped with MongoEngine 0.20.0

Dependencies

All of the dependencies can easily be installed via python -m pip. At the very least, you’ll need these two packages to use MongoEngine:

  • pymongo>=3.4

If you utilize a DateTimeField, you might also use a more flexible date parser:

  • dateutil>=2.1.0

If you need to use an ImageField or ImageGridFsProxy:

  • Pillow>=7.0.0

If you need to use signals:

  • blinker>=1.3

Examples

Some simple examples of what MongoEngine code looks like:

from mongoengine import *
connect('mydb')

class BlogPost(Document):
    title = StringField(required=True, max_length=200)
    posted = DateTimeField(default=datetime.datetime.utcnow)
    tags = ListField(StringField(max_length=50))
    meta = {'allow_inheritance': True}

class TextPost(BlogPost):
    content = StringField(required=True)

class LinkPost(BlogPost):
    url = StringField(required=True)

# Create a text-based post
>>> post1 = TextPost(title='Using MongoEngine', content='See the tutorial')
>>> post1.tags = ['mongodb', 'mongoengine']
>>> post1.save()

# Create a link-based post
>>> post2 = LinkPost(title='MongoEngine Docs', url='hmarr.com/mongoengine')
>>> post2.tags = ['mongoengine', 'documentation']
>>> post2.save()

# Iterate over all posts using the BlogPost superclass
>>> for post in BlogPost.objects:
...     print('===', post.title, '===')
...     if isinstance(post, TextPost):
...         print(post.content)
...     elif isinstance(post, LinkPost):
...         print('Link:', post.url)
...

# Count all blog posts and its subtypes
>>> BlogPost.objects.count()
2
>>> TextPost.objects.count()
1
>>> LinkPost.objects.count()
1

# Count tagged posts
>>> BlogPost.objects(tags='mongoengine').count()
2
>>> BlogPost.objects(tags='mongodb').count()
1

Tests

To run the test suite, ensure you are running a local instance of MongoDB on the standard port and have pytest installed. Then, run pytest tests/.

To run the test suite on every supported Python and PyMongo version, you can use tox. You’ll need to make sure you have each supported Python version installed in your environment and then:

# Install tox
$ python -m pip install tox
# Run the test suites
$ tox

Community

Contributing

We welcome contributions! See the Contribution guidelines

Release files for mongoengine 0.29.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mongoengine 0.29.3
File Size Uploaded
mongoengine-0.29.3.tar.gz 188.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mongoengine 0.29.3
File Interpreter ABI Platform
mongoengine-0.29.3-py3-none-any.whl Python 3 none any Details

Total release size: 300.7 kB

Release files / mongoengine-0.29.3.tar.gz

Download URL mongoengine-0.29.3.tar.gz
Size 188.2 kB
Tags Source
SHA-256 checksum
How to use checksums
4267702aea433012845cb12b6334bff86a0a3084b5d141c1e4553ea20374a9b4
BLAKE2b-256 checksum
How to use checksums
b476160e35d90a671913146b884b1ca586909036dd56070600035821870b1aad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / mongoengine-0.29.3-py3-none-any.whl

Download URL mongoengine-0.29.3-py3-none-any.whl
Size 112.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2d5a216cf2368867d43e5321b13044ecc3e72c3f19ace21b1c5e7403951ca685
BLAKE2b-256 checksum
How to use checksums
c7b5214ea32710fa3ad7c13820cbb9f9a457d4809a5d54995e0d081f33c75116
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

0.29.3 This release

2 release files

0.29.2

2 release files

0.29.1

2 release files

0.29.0

2 release files

0.26.0

2 release files

0.25.0

2 release files

0.24.2

2 release files

0.24.1

2 release files

0.24.0

2 release files

0.22.1

2 release files

0.22.0

2 release files

0.21.0

2 release files

0.19.0

2 release files

0.18.2

2 release files

0.18.0

2 release files

0.17.0

2 release files

0.16.2

2 release files

0.16.1

2 release files

0.15.3

2 release files

0.13.0

2 release files

0.11.0

1 release file

0.10.9

1 release file

0.10.7

1 release file

0.10.6

1 release file

0.10.5

1 release file

0.10.4

1 release file

0.10.1

1 release file

0.10.0

1 release file

0.9.0

1 release file

0.8.8

1 release file

0.8.7

3 release files

0.8.6

1 release file

0.8.5

1 release file

0.8.4

1 release file

0.8.3

1 release file

0.8.2

1 release file

0.8.1

1 release file

0.8.0

1 release file

0.7.10

1 release file

0.7.9

1 release file

0.7.8

1 release file

0.7.5

1 release file

0.7.4

1 release file

0.7.3

1 release file

0.7.2

1 release file

0.7.1

1 release file

0.7.0

1 release file

0.6.20

1 release file

0.6.19

1 release file

0.6.17

1 release file

0.6.16

1 release file

0.6.15

1 release file

0.6.13

1 release file

0.6.12

1 release file

0.6.10

1 release file

0.6.8

1 release file

0.6.7

1 release file

0.6.6

1 release file

0.6.4

1 release file

0.6.3

1 release file

0.6.1

1 release file

0.5.2

1 release file

0.5.1

1 release file

0.5

1 release file

0.4

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page