skillfed

mongoengine

MongoEngine is a Python Object-Document Mapper for working with MongoDB.

mongoengine v0.29.3 2.5M downloads/30d#3,032 on PyPI4,348
Permissive license MIT Active released

What it is and what it does

MongoEngine is a Python Object-Document Mapper that sits on top of PyMongo and lets you define MongoDB documents as Python classes with typed fields, validation rules, and relationships. Instead of working directly with dictionaries and raw MongoDB queries, you define a class (like a Django model or SQLAlchemy ORM class) with fields like StringField, DateTimeField, and ListField, then create, query, and manipulate documents as instances of those classes. It handles the translation between Python objects and MongoDB's BSON format, supports inheritance, field validation, and provides a query interface similar to traditional ORMs.

The package is production-stable, actively maintained, and widely used. It depends only on pymongo and has low install friction. Optional features like DateTimeField parsing, image handling, and signal support require additional packages (dateutil, Pillow, blinker) that you can add as needed. MongoEngine is tested against MongoDB v4.4, v5.0, v6.0, and v7.0, and supports Python 3.7 and later.

Use it for:

  • Define MongoDB schemas with typed fields and validation rules, then query documents as Python objects instead of raw dictionaries.
  • Build web applications (Flask, Django) that need MongoDB persistence with an ORM-like interface familiar to SQL developers.
  • Implement document inheritance and polymorphism where subclasses of a base document type are stored in the same collection.
  • Prototype or migrate from SQL databases to MongoDB while keeping a similar object-oriented data model.
  • Handle complex nested documents and lists with automatic serialization and deserialization between Python and BSON.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

MongoEngine provides an Object-Document Mapper (ODM) layer on top of PyMongo, letting you define MongoDB documents as Python classes with typed fields and query them using a familiar ORM-like interface.

Yes. MongoEngine is production-stable, actively maintained, has no known vulnerabilities, low install friction, and a permissive MIT license. Install it if you want an ORM-like layer over MongoDB and prefer working with Python classes and typed fields instead of raw dictionaries and queries. Skip it only if you need maximum performance or prefer the flexibility and control of raw PyMongo.

Install

mongoengine on PyPI

pip

pip install mongoengine

uv

uv add mongoengine

poetry

poetry add mongoengine

Installing mongoengine

Before you install

Low friction: pure Python wheel, single runtime dependency (pymongo), and active maintenance with a recent release (157 days ago) and ongoing repository activity.

License in practice

MIT license is permissive; you can use MongoEngine in commercial and proprietary projects with minimal restrictions.

Quickstart

pip install mongoengine

from mongoengine import Document, StringField, connect

connect('mydb')

class BlogPost(Document):
    title = StringField(required=True, max_length=200)

post = BlogPost(title='Example')
post.save()

Requires a running MongoDB instance (local or remote) to connect to; MongoEngine is tested against MongoDB v4.4, v5.0, v6.0, and v7.0.

Verify before relying

  • Whether optional dependencies (dateutil, Pillow, blinker) are automatically installed or must be added separately for their respective features.
  • Performance characteristics and query optimization strategies compared to raw PyMongo for large datasets.

Package facts

License MIT (permissive)
Python support supports the current Python release (>=3.7)
Install friction low — pure-Python wheel
Runtime dependencies 1 — pymongo
Maintenance actively maintained — 157 days since the last release
Last repo commit
First released
Downloads 2,512,474/month — #3,032 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: mongoengine-0.29.3-py3-none-any.whl

Development Status :: 5 - Production/StableIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyTopic :: DatabaseTopic :: Software Development :: Libraries :: Python Modules

Tags

mongodb orm pythondocument mapper mongodbmongoengine odmpython mongodb object mappingmongo document schema validationpymongo wrapper orm
mongodb-ormdocument-mapperschema-validation

More Python Modules packages