Install & Compatibility
Where this runs
tested against v1.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 33.8MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 3.6s · import 0.000s · 36MB
34MB installed
● package 34MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
MongoEngine
✓ from flask_mongoengine import MongoEngine
✗ from flask_mongoengine import MongoEngine
This quickstart sets up a basic Flask application with Flask-MongoEngine, connects to a local MongoDB instance (or one specified by MONGODB_URI), defines a simple 'User' document, and demonstrates creating and retrieving users via a Flask route.
import os
from flask import Flask
from flask_mongoengine import MongoEngine
from mongoengine import Document, StringField, IntField
app = Flask(__name__)
# Configure MongoDB connection
# Use an environment variable for production readiness
app.config["MONGODB_HOST"] = os.environ.get("MONGODB_URI", "mongodb://localhost/testdb")
db = MongoEngine(app)
class User(Document):
name = StringField(required=True)
age = IntField()
meta = {'collection': 'users'}
@app.route('/')
def index():
# Ensure collection is empty for repeatable test runs
User.drop_collection()
# Create a user
user = User(name="Alice", age=30)
user.save()
# Create another user
User(name="Bob", age=25).save()
# Find users
all_users = User.objects.all()
names = [u.name for u in all_users]
return f"<h1>Users in MongoDB:</h1><p>{', '.join(names)}</p>"
Debug
Known issues
breakingFlask-MongoEngine v1.0.0 dropped support for Python versions 2.7 through 3.5. Applications using these Python versions will fail to install or run.fixUpgrade your Python environment to 3.6 or newer. If upgrading Python is not an option, you must use Flask-MongoEngine <1.0.0 (e.g., `pip install "flask-mongoengine<1.0.0"`).
affects: >=1.0.0
breakingFlask-MongoEngine v1.0.0 dropped support for PyMongo versions older than 3.6.0. An incompatible PyMongo version will lead to configuration errors.fixEnsure PyMongo is updated to version 3.6.0 or newer: `pip install --upgrade pymongo`.
affects: >=1.0.0
breakingFlask-MongoEngine v0.8 dropped support for MongoEngine 0.7. Using an older MongoEngine version will lead to various compatibility issues and errors.fixEnsure MongoEngine is updated to a compatible version (0.10+ for v0.8, and 0.15+ for v1.0.0): `pip install --upgrade mongoengine`.
affects: >=0.8
deprecatedMongoEngine's `help_text` and `safe` attributes for fields were deprecated prior to Flask-MongoEngine v0.7.5. While Flask-MongoEngine handles some of these changes, direct usage in custom forms might still lead to warnings or errors in newer MongoEngine versions.fixUpdate MongoEngine and Flask-MongoEngine to their latest versions. Replace `help_text` with `description` in `StringField`, `IntField` etc. if directly passing them to `mongoengine.fields`.
affects: <0.7.5 (and older MongoEngine versions)
Upgrade
Version history
1.0.0latest on PyPI · released Nov 21, 2020
Audit
Dependencies
FlaskrequiredWeb framework integration
MongoEnginerequiredODM for MongoDB
Flask-WTFrequiredWTF form integration
pymongorequiredMongoDB Python driver