pydantic-mongo
Document object mapper for pydantic and pymongo
Decision gist · record as of 2026-08-14
Yes, if you are already using Pydantic and MongoDB together. The package reduces boilerplate and provides a clean, type-safe interface for common CRUD patterns. Maintenance is aging but active, with no security issues. Install friction is low. The main trade-off is that you are adding a thin abstraction layer—if you need fine-grained control over MongoDB queries or aggregation pipelines, you may find the repository pattern limiting and prefer working directly with pymongo.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires a running MongoDB instance accessible at the connection string you provide.
- Low install friction with a pure Python wheel.
- Maintenance is aging—last commit was 2025-10-13, but the project remains active and supports current Python versions (3.9, 3.10, 3.11).
License · maintenance · safety
MIT (permissive) — MIT license is permissive; you can use, modify, and distribute this package freely in commercial and private projects with minimal restrictions.
last release 2025-04-18 (483 days) · last repo commit 2025-10-13 · 169 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 182,303 downloads/mo, #10,104 on PyPI
Alternatives
Verify before relying
pip install pydantic-mongo
from pydantic import BaseModel
from pydantic_mongo import AbstractRepository
from pymongo import MongoClient
class MyModel(BaseModel):
name: str
class MyRepository(AbstractRepository[MyModel]):
class Meta:
collection_name = 'items'
client = MongoClient('mongodb://localhost:27017')
db = client['mydb']
repo = MyRepository(db)
item = MyModel(name='test')
repo.save(item)- Whether cursor-based pagination handles large result sets efficiently in practice.
- Performance characteristics when working with deeply nested Pydantic models.
- Compatibility guarantees with future versions of pymongo and pydantic.
What it is and what it does
Pydantic Mongo is a thin wrapper around pymongo that applies the Repository pattern, letting you define MongoDB collections as Pydantic models and interact with them through a type-safe, validated interface. It handles the boilerplate of connecting Pydantic's validation and serialization to MongoDB's document model, so you define your schema once as a Pydantic class and then use repository methods (save, find_one_by_id, find_by, delete, etc.) to perform CRUD operations without writing raw MongoDB queries.
The package supports both synchronous (via AbstractRepository) and asynchronous (via AsyncAbstractRepository) workflows, making it suitable for blocking and non-blocking applications. It depends on pymongo for the driver layer and pydantic for validation, so you inherit both their capabilities and constraints—notably, you still need a MongoDB server running, and your models must be valid Pydantic classes.
Use it for
- Building a REST API where each endpoint maps to a Pydantic model stored in MongoDB, with automatic validation on save.
- Writing async FastAPI handlers that query MongoDB without writing raw pymongo code or managing connection pooling manually.
- Migrating from a different ORM to MongoDB while keeping your existing Pydantic schemas and validation logic.
- Implementing cursor-based pagination for large result sets in a web application.
- Defining type-safe repository classes for unit testing with mock repositories that share the same interface.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes, if you are already using Pydantic and MongoDB together.
The package reduces boilerplate and provides a clean, type-safe interface for common CRUD patterns. Maintenance is aging but active, with no security issues. Install friction is low. The main trade-off is that you are adding a thin abstraction layer—if you need fine-grained control over MongoDB queries or aggregation pipelines, you may find the repository pattern limiting and prefer working directly with pymongo.
Install
pydantic-mongo on PyPI
Before you install
Low install friction with a pure Python wheel. Maintenance is aging—last commit was 2025-10-13, but the project remains active and supports current Python versions (3.9, 3.10, 3.11). No known vulnerabilities.
Requires a running MongoDB instance accessible at the connection string you provide.
License in practice
MIT license is permissive; you can use, modify, and distribute this package freely in commercial and private projects with minimal restrictions.
Quickstart
pip install pydantic-mongo
from pydantic import BaseModel
from pydantic_mongo import AbstractRepository
from pymongo import MongoClient
class MyModel(BaseModel):
name: str
class MyRepository(AbstractRepository[MyModel]):
class Meta:
collection_name = 'items'
client = MongoClient('mongodb://localhost:27017')
db = client['mydb']
repo = MyRepository(db)
item = MyModel(name='test')
repo.save(item)
Verify before relying
- Whether cursor-based pagination handles large result sets efficiently in practice.
- Performance characteristics when working with deeply nested Pydantic models.
- Compatibility guarantees with future versions of pymongo and pydantic.
Package facts
| License | MIT permissive |
| Python support | Supports the current Python release >=3.8 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | 2 packagespymongopydantic |
| Maintenance | Aging 483 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 182,303 / month, #10,104 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | License :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.9 |
Evidence: pydantic_mongo-3.1.0-py2.py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “mongodb repository pattern”
- pydantic-mongoProvides a Repository pattern for MongoDB with Pydantic model…
- flask-mongoengineFlask-MongoEngine integrates MongoEngine document models with Flask,…
- curatorbinPackages the MongoDB Curator tool as a Python library, allowing you…
Give your agent the search over MCP, or paste the wish link into any chat.
More Database packages
psycopg2-binary is a PostgreSQL database adapter for Python that implements the DB API 2.0 specification, enabling Python applications to connect to and query PostgreSQL databases with thread-safe concurrent operations.
Python client library for connecting to and executing commands against Redis key-value stores, supporting both synchronous and asynchronous operations.
Install it if your application needs to interact with Redis; the only prerequisite is a running Redis server instance.
YDB Python SDK is the official client library for connecting to and querying YDB databases from Python applications.
Install it if you need to connect Python applications to YDB databases.
Connects Python applications to Snowflake data warehouses using the DB API 2.0 specification, enabling SQL queries, data transfers, and warehouse operations.
sqlparse tokenizes SQL text into a tree of statements, clauses, and expressions, and provides functions to split scripts, format queries, and inspect parsed tokens without validating dialect or syntax.
Install it if you need to manipulate, format, or analyze SQL text programmatically.
Provides base adapter protocols and shared functionality that database adapters use to integrate with dbt-core, handling connections, dialect translation, relation caching, and core interface management.
See also beanie · odmantic · pymongo · Flask-PyMongo · pydantic-collections · pymongoexplain · mongoengine · motor · apache-airflow-providers-mongo · gdbmongo