--- id: mongoengine version: "0.29.3" license: MIT license_treatment: permissive maintenance: active --- # mongoengine — MongoEngine is a Python Object-Document Mapper for working with MongoDB. License: permissive · Maintenance: active · Downloads: 2.5M/mo ## 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 above — 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 pip install mongoengine uv add mongoengine 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_current - Install friction: low - Maintenance: active - Downloads: 2.5M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags mongodb orm python, document mapper mongodb, mongoengine odm, python mongodb object mapping, mongo document schema validation, pymongo wrapper orm, mongodb-orm, document-mapper, schema-validation [View on SkillFed](https://skillfed.io/packages/mongoengine) · [View on PyPI](https://pypi.org/project/mongoengine/)