# Python MongoDB libraries

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

| Library | Monthly downloads | Stars | Last release | License |
| --- | --- | --- | --- | --- |
| [PyMongo](#pymongo) | 74.1M | 4.4K | Nov 2026 | Apache-2.0 |
| [Motor](#motor) | 10.5M | 2.5K | May 2025 | Apache-2.0 |
| [Beanie](#beanie) | 2.0M | 2.7K | Aug 2026 | Apache-2.0 |
| [MongoEngine](#mongoengine) | 1.7M | 4.3K | Mar 2026 | MIT |
| [ODMantic](#odmantic) | 58.7K | 1.2K | Jan 2026 | ISC |
| [Django MongoDB Backend](#django-mongodb-backend) | 45.7K | 229 | Aug 2026 | Apache-2.0 |
| [uMongo](#umongo) | 22.2K | 448 | Mar 2026 | MIT |

Downloads: PyPI, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

[PyMongo](#pymongo) has the most monthly downloads in this comparison, at 74.1M.

## Capabilities

| Library | Synchronous document operations | Pydantic document models |
| --- | --- | --- |
| [PyMongo](#pymongo) | Yes | No |
| [Motor](#motor) | No | No |
| [Beanie](#beanie) | No | Yes |
| [MongoEngine](#mongoengine) | Yes | No |
| [ODMantic](#odmantic) | Yes | Yes |
| [Django MongoDB Backend](#django-mongodb-backend) | Yes | No |
| [uMongo](#umongo) | Yes | No |

## Libraries

### PyMongo

[GitHub](https://github.com/mongodb/mongo-python-driver) · [PyPI](https://pypi.org/project/pymongo) · [Docs](https://www.mongodb.com/docs/languages/python/pymongo-driver/current/)

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
- Capabilities: [From the PyMongo docs](https://www.mongodb.com/docs/languages/python/pymongo-driver/current/)

**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.

**Watch out for**

- **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.

```sh
python3.13 -m pip install pymongo==4.20.0
```

**Quickstart**

```python
from pymongo import MongoClient

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

```

From [README.md](https://www.mongodb.com/docs/languages/python/pymongo-driver/current/) · [Find projects using PyMongo →](https://dashboard.exa.ai/playground/search?q=Python%20projects%20using%20pymongo%20for%20task-result%20cleanup%2C%20search%20filters%20and%20document%20updates&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

### Motor

[GitHub](https://github.com/mongodb/motor) · [PyPI](https://pypi.org/project/motor) · [Docs](https://motor.readthedocs.io/en/stable/)

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
- Capabilities: [From the Motor docs](https://motor.readthedocs.io/en/stable/)

```sh
python3.13 -m pip install motor==3.7.1 pymongo==4.20.0
```

**Quickstart**

```python
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())

```

From [README.md](https://motor.readthedocs.io/en/stable/) · [Find projects using Motor →](https://dashboard.exa.ai/playground/search?q=motor%20GitHub%20projects)

### Beanie

[GitHub](https://github.com/BeanieODM/beanie) · [PyPI](https://pypi.org/project/beanie) · [Docs](https://beanie-odm.dev/)

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
- Capabilities: [From the Beanie docs](https://beanie-odm.dev/)

**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.

**Watch out for**

- **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.

```sh
python3.13 -m pip install beanie==2.2.0 pymongo==4.20.0
```

**devdupont/fastapi-beanie-jwt** (200 stars)

[devdupont/fastapi-beanie-jwt](https://github.com/devdupont/fastapi-beanie-jwt) 

```python
@router.patch("", response_model=UserOut)
async def update_user(update: UserUpdate, user: User = Depends(current_user)):  # type: ignore[no-untyped-def]
    """Update allowed user fields."""
    fields = update.model_dump(exclude_unset=True)
    if new_email := fields.pop("email", None):
        if new_email != user.email:
            if await User.by_email(new_email) is not None:
                raise HTTPException(400, "Email already exists")
            user.update_email(new_email)
    user = user.model_copy(update=fields)
    await user.save()
    return user
```

[myserver/routes/user.py](https://github.com/devdupont/fastapi-beanie-jwt/blob/71dd0fc90c08cae2938c1e2d315179b86967db8c/myserver/routes/user.py) · [More projects using Beanie →](https://dashboard.exa.ai/playground/search?q=Python%20projects%20using%20beanie%20for%20task-result%20cleanup%2C%20search%20filters%20and%20document%20updates&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```python
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())

```

From [README.md](https://beanie-odm.dev/)

### MongoEngine

[GitHub](https://github.com/MongoEngine/mongoengine) · [PyPI](https://pypi.org/project/mongoengine) · [Docs](https://mongoengine-odm.readthedocs.io/apireference.html)

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
- Capabilities: [From the MongoEngine docs](https://mongoengine-odm.readthedocs.io/apireference.html)

**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.

**Watch out for**

- **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.

```sh
python3.13 -m pip install mongoengine==0.29.3
```

**pallets-eco/flask-admin** (6.1K stars)

[pallets-eco/flask-admin](https://github.com/pallets-eco/flask-admin) 

```python
def create_model(self, form: Form) -> Document | bool:
    """
    Create model helper

    :param form:
        Form instance
    """
    try:
        model = self.model()
        form.populate_obj(model)
        self._on_model_change(form, model, True)
        model.save()
    except Exception as ex:
        if not self.handle_view_exception(ex):
            flash(
                gettext(
                    "Failed to create record. %(error)s", error=format_error(ex)
                ),
                "error",
            )
            log.exception("Failed to create record.")

        return False
    else:
        self.after_model_change(form, model, True)

    return model
```

[flask_admin/contrib/mongoengine/view.py](https://github.com/pallets-eco/flask-admin/blob/861ba3806b47b28715ee3c394cf3d901d4e592b4/flask_admin/contrib/mongoengine/view.py) · [More projects using MongoEngine →](https://dashboard.exa.ai/playground/search?q=Python%20projects%20using%20mongoengine%20for%20task-result%20cleanup%2C%20search%20filters%20and%20document%20updates&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```python
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()

```

From [README.rst](https://mongoengine-odm.readthedocs.io/apireference.html)

### ODMantic

[GitHub](https://github.com/art049/odmantic) · [PyPI](https://pypi.org/project/odmantic) · [Docs](https://art049.github.io/odmantic/engine/)

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
- Capabilities: [From the ODMantic docs](https://art049.github.io/odmantic/engine/)

**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.

**Watch out for**

- **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.

```sh
python3.13 -m pip install odmantic==1.1.0 pymongo==4.20.0
```

**mongodb-labs/full-stack-fastapi-mongodb** (820 stars)

[mongodb-labs/full-stack-fastapi-mongodb](https://github.com/mongodb-labs/full-stack-fastapi-mongodb) 

```python
async def update(
    self, db: AgnosticDatabase, *, db_obj: ModelType, obj_in: Union[UpdateSchemaType, Dict[str, Any]] # noqa
) -> ModelType:
    obj_data = jsonable_encoder(db_obj)
    if isinstance(obj_in, dict):
        update_data = obj_in
    else:
        update_data = obj_in.model_dump(exclude_unset=True)
    for field in obj_data:
        if field in update_data:
            setattr(db_obj, field, update_data[field])
    # TODO: Check if this saves changes with the setattr calls
    await self.engine.save(db_obj)
    return db_obj

```

[{{cookiecutter.project_slug}}/backend/app/app/crud/base.py](https://github.com/mongodb-labs/full-stack-fastapi-mongodb/blob/ac15de2b2241e3354ef7cd336e80131275dcc34d/{{cookiecutter.project_slug}}/backend/app/app/crud/base.py) · [More projects using ODMantic →](https://dashboard.exa.ai/playground/search?q=Python%20projects%20using%20odmantic%20for%20task-result%20cleanup%2C%20search%20filters%20and%20document%20updates&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```python
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"))

```

From [save_with_transaction.py](https://art049.github.io/odmantic/engine/)

### Django MongoDB Backend

[GitHub](https://github.com/mongodb/django-mongodb-backend) · [PyPI](https://pypi.org/project/django-mongodb-backend) · [Docs](https://www.mongodb.com/docs/languages/python/django-mongodb/current/get-started/)

Connects Django to MongoDB as a database backend.

- Downloads / mo: 45.7K
- Stars: 229
- Last release: 6.1.0
- License: Apache-2.0
- Capabilities: [From the Django MongoDB Backend docs](https://www.mongodb.com/docs/languages/python/django-mongodb/current/get-started/)

```sh
python3.13 -m pip install django-mongodb-backend==6.1.0 pymongo==4.20.0 Django==6.1.3
```

**Quickstart**

```python
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"))

```

From [README.md](https://www.mongodb.com/docs/languages/python/django-mongodb/current/get-started/) · [Find projects using Django MongoDB Backend →](https://dashboard.exa.ai/playground/search?q=django-mongodb-backend%20GitHub%20projects)

### uMongo

[GitHub](https://github.com/Scille/umongo) · [PyPI](https://pypi.org/project/umongo) · [Docs](https://umongo.readthedocs.io/en/latest/apireference.html)

Maps MongoDB documents in synchronous or asynchronous code.

- Downloads / mo: 22.2K
- Stars: 448
- Last release: 4.0.0
- License: MIT
- Capabilities: [From the uMongo docs](https://umongo.readthedocs.io/en/latest/apireference.html)

```sh
python3.13 -m pip install umongo==4.0.0 pymongo==4.20.0
```

**Quickstart**

```python
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()

```

From [apireference.html](https://umongo.readthedocs.io/en/latest/apireference.html) · [Find projects using uMongo →](https://dashboard.exa.ai/playground/search?q=umongo%20GitHub%20projects)

## FAQ

### Which Python MongoDB library should I use?

[PyMongo](#pymongo) suits most applications, with synchronous and native asyncio APIs from MongoDB. [Beanie](#beanie) suits async applications that model documents with Pydantic. [MongoEngine](#mongoengine) suits synchronous applications that want declarative document classes.

### What is PyMongo?

[PyMongo](#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.

### What is MongoEngine?

[MongoEngine](#mongoengine) is a synchronous object document mapper with declarative document and field classes, validation on save, and querysets.

### Is Motor deprecated?

Yes. MongoDB has announced the deprecation of [Motor](#motor) and recommends migrating to the async API in [PyMongo](#pymongo). Motor receives only critical bug fixes during the deprecation window.

## How this page was built

Data checked Nov 20, 2026.

Reproduce it with the Exa API:

```json
{
  "endpoint": "/search",
  "body": {
    "query": "Best Python MongoDB libraries PyMongo MongoEngine Beanie ODMantic examples",
    "numResults": 5
  }
}
```

Docs: https://exa.ai/docs/reference/search
