Python MongoDB libraries

Updated Nov 2026

Python MongoDB libraries connect applications to MongoDB and read and write its documents. An object document mapper adds schemas, validation, and typed models on top of the plain dictionaries that a driver returns. These libraries let web apps and backend services store user records, content, and events as JSON-like documents.

Popularity

PyMongo has the most monthly downloads in this comparison, at 74.1M.

LibraryMonthly downloadsStarsLast releaseLicense
PyMongo
74.1M
4.4KNov 2026Apache-2.0
Motor
10.5M
2.5KMay 2025Apache-2.0
Beanie
2.0M
2.7KAug 2026Apache-2.0
MongoEngine
1.7M
4.3KMar 2026MIT
ODMantic
58.7K
1.2KJan 2026ISC
Django MongoDB Backend
45.7K
229Aug 2026Apache-2.0
uMongo
22.2K
448Mar 2026MIT
Downloads: PyPI, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

Libraries and code examples

Provides synchronous and asynchronous MongoDB operations through the native Python driver.

Downloads / mo
74.1M
Stars
4.4K
Last release
4.20.0
License
Apache-2.0

Strengths

  • Offers synchronous and asynchronous APIs. Choose the native client interface that fits the application.
  • Coordinates multi-document transactions. Commit related writes together or discard their changes on failure.

Limitations

  • Async clients need one loop. Keep each AsyncMongoClient within its original thread and event loop.
  • Transaction operations must run sequentially. Avoid parallel operations inside the same transaction.

Quickstart

From README.md
$ python3.13 -m pip install pymongo==4.20.0
from pymongo import MongoClient

with MongoClient("mongodb://localhost:27017") as client:
    result = client.library_demo.notes.insert_one({"name": "Hello"})
    print(result.inserted_id)

Provides a non-blocking MongoDB driver for Tornado or asyncio.

Downloads / mo
10.5M
Stars
2.5K
Last release
3.7.1
License
Apache-2.0

Quickstart

From README.md
$ python3.13 -m pip install motor==3.7.1 pymongo==4.20.0
import asyncio
from motor.motor_asyncio import AsyncIOMotorClient

async def main():
    client = AsyncIOMotorClient("mongodb://localhost:27017")
    try:
        result = await client.library_demo.notes.insert_one({"name": "Hello"})
        print(result.inserted_id)
    finally:
        client.close()

asyncio.run(main())

Maps MongoDB collections to asynchronous Pydantic-based document models.

Downloads / mo
2.0M
Stars
2.7K
Last release
2.2.0
License
Apache-2.0

Strengths

  • Uses Pydantic document models. Define typed document fields and embedded Pydantic models.
  • Includes data and schema migrations. Manage document changes with the mapper’s migration tooling.

Limitations

  • Relations need top-level fields. Keep supported document links at the top level of the model.
  • Fetched links restrict chained writes. Separate linked-document fetching from chained update or delete operations.

Quickstart

From README.md
$ python3.13 -m pip install beanie==2.2.0 pymongo==4.20.0
import asyncio
from pymongo import AsyncMongoClient
from beanie import Document, init_beanie

class Note(Document):
    name: str

async def main():
    client = AsyncMongoClient("mongodb://localhost:27017")
    try:
        await init_beanie(database=client.library_demo, document_models=[Note])
        await Note(name="Hello").insert()
    finally:
        await client.close()

asyncio.run(main())

Beanie examples

From open-source projects on GitHub

Maps MongoDB documents to Python classes with declared fields, validation, and references.

Downloads / mo
1.7M
Stars
4.3K
Last release
0.29.3
License
MIT

Strengths

  • Validates documents before saving. Check declared field constraints when validating or saving a document.
  • Links documents through declared references. Assign another document to a ReferenceField and retrieve it through that field.

Limitations

  • Uses synchronous database operations. Choose an asynchronous mapper when database calls must be awaited.
  • Loaded documents skip validation. Validate existing records explicitly when their stored schema cannot be trusted.

Quickstart

From README.rst
$ python3.13 -m pip install mongoengine==0.29.3
from mongoengine import connect, Document, StringField

connect(db="library_demo", host="mongodb://localhost:27017")

class Note(Document):
    name = StringField(required=True)

Note(name="Hello").save()

MongoEngine examples

From open-source projects on GitHub

Maps MongoDB documents through typed Pydantic models and synchronous or asynchronous engines.

Downloads / mo
58.7K
Stars
1.2K
Last release
1.1.0
License
ISC

Strengths

  • Offers synchronous and asynchronous engines. Use matching engine operations in blocking or asynchronous applications.
  • Persists referenced models automatically. Save a model and its declared references through the engine.

Limitations

  • Saving can overwrite existing documents. save and save_all update records whose primary keys already exist.
  • Model inheritance remains unsupported. Use separate models or composition instead of inheriting document models.
$ python3.13 -m pip install odmantic==1.1.0 pymongo==4.20.0
from pymongo import MongoClient
from odmantic import Model, SyncEngine

class Note(Model):
    name: str

with MongoClient("mongodb://localhost:27017") as client:
    engine = SyncEngine(client=client, database="library_demo")
    engine.save(Note(name="Hello"))

ODMantic examples

From open-source projects on GitHub

Django MongoDB Backend

Connects Django to MongoDB as a database backend.

Downloads / mo
45.7K
Stars
229
Last release
6.1.0
License
Apache-2.0

Quickstart

From README.md
$ python3.13 -m pip install django-mongodb-backend==6.1.0 pymongo==4.20.0 Django==6.1.3
from django.conf import settings

settings.configure(DATABASES={"default": {
    "ENGINE": "django_mongodb_backend",
    "HOST": "mongodb://localhost:27017", "NAME": "library_demo",
}})
import django
django.setup()
from django.db import connection
print(connection.get_database().command("ping"))

Maps MongoDB documents in synchronous or asynchronous code.

Downloads / mo
22.2K
Stars
448
Last release
4.0.0
License
MIT

Quickstart

From apireference.html
$ python3.13 -m pip install umongo==4.0.0 pymongo==4.20.0
from pymongo import MongoClient
from umongo import Document, fields
from umongo.frameworks.pymongo import PyMongoInstance

with MongoClient("mongodb://localhost:27017") as client:
    instance = PyMongoInstance(client.library_demo)

    @instance.register
    class Note(Document):
        name = fields.StringField(required=True)

    Note(name="Hello").commit()

FAQ

PyMongo suits most applications, with synchronous and native asyncio APIs from MongoDB. Beanie suits async applications that model documents with Pydantic. MongoEngine suits synchronous applications that want declarative document classes.

PyMongo is the official MongoDB driver for Python, with synchronous and native asyncio APIs. It works with raw dictionaries and BSON rather than model classes.

MongoEngine is a synchronous object document mapper with declarative document and field classes, validation on save, and querysets.

Yes. MongoDB has announced the deprecation of Motor and recommends migrating to the async API in PyMongo. Motor receives only critical bug fixes during the deprecation window.

For coding agents

Found your MongoDB library? Help your agent use it.

Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.

Run in your terminal

claude plugin install exa@claude-plugins-official