mongoengine
MongoEngine is a Python Object-Document Mapper for working with MongoDB.
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 mongoengineuv
uv add mongoenginepoetry
poetry add mongoengineInstalling 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
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
beanieBeanie is an asynchronous Python…
permissive · top 5,000 on PyPI
flask-mongoengineFlask-MongoEngine integrates MongoEngine…
permissive · top 15,000 on PyPI
odmanticODMantic is an async-first Object Document…
permissive · top 15,000 on PyPI
marshmallow-mongoengineGenerates marshmallow schemas automatically…
permissive · top 15,000 on PyPI
Flask-PyMongoFlask-PyMongo integrates MongoDB database…
permissive · top 15,000 on PyPI
pydantic-mongoProvides a Repository pattern for MongoDB with…
permissive · top 15,000 on PyPI
pymongoarrowPyMongoArrow converts MongoDB query results…
permissive · top 15,000 on PyPI
pymongoPyMongo is the official MongoDB Python driver,…
permissive · top 1,000 on PyPI
pymongoexplainWraps PyMongo's Collection class to explain…
permissive · top 15,000 on PyPI
CouchDBA Python client library for interacting with…
permissive · top 15,000 on PyPI