odmantic
ODMantic, an AsyncIO MongoDB Object Document Mapper for Python using type hints
What it is and what it does
ODMantic bridges Python type hints and MongoDB by letting you define models as Pydantic classes, then use those classes to query, insert, update, and delete documents with full type safety and validation. It wraps motor (the async MongoDB driver) and pymongo, supporting both async/await patterns (ideal for ASGI frameworks like FastAPI) and synchronous code.
You define a model by subclassing Model and annotating fields with Python types; ODMantic handles collection naming, field validation via Pydantic, and automatic _id generation. Queries use Python comparison operators (e.g., `Publisher.founded <= 2000`) rather than MongoDB query syntax, and the engine provides methods like `find()`, `find_one()`, `save()`, and `save_all()` to perform database operations. Built-in JSON serialization and schema generation are included.
Use it for:
- Build FastAPI or Starlette applications with async MongoDB persistence using type-hinted models.
- Define MongoDB schemas with Pydantic validation to catch invalid data before it reaches the database.
- Query MongoDB collections using Python operators instead of MongoDB query syntax.
- Migrate from synchronous ORMs to async-first code without rewriting model definitions.
- Generate JSON schemas and API documentation automatically from your ODMantic models.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
ODMantic is an async-first Object Document Mapper for MongoDB that lets you define database models using Python type hints and Pydantic validation, then query and persist them with a functional API.
Yes. ODMantic is actively maintained, has low install friction, carries no known vulnerabilities, and solves a real problem for Python developers using MongoDB with async frameworks. The ISC license is permissive. Install it if you need an async MongoDB ODM with strong type safety and Pydantic integration.
Install
odmantic on PyPI
pip
pip install odmanticuv
uv add odmanticpoetry
poetry add odmanticInstalling odmantic
Before you install
Low friction install with a pure-Python wheel. Actively maintained as of 2026-05-19 with 1175 repository stars. Depends on pydantic, motor, pymongo, and typing-extensions—all stable, widely-used libraries.
License in practice
Licensed under ISC (permissive), allowing commercial and private use with minimal restrictions.
Quickstart
pip install odmantic
from odmantic import Model, Field, AIOEngine
from typing import Optional
class Publisher(Model):
name: str
founded: int = Field(ge=1440)
location: Optional[str] = None
engine = AIOEngine()
await engine.save_all([Publisher(name="Test", founded=2000)])
results = await engine.find(Publisher, Publisher.founded >= 2000)
Requires a running MongoDB instance (4.0 or later) and Python 3.8 or later. Async operations require an event loop context.
Verify before relying
- Whether Pydantic 2.5+ is strictly required or if earlier 2.x versions work.
- Performance characteristics and scalability limits for large document collections.
- Completeness of query operator support compared to raw PyMongo.
Package facts
| License | not declared (permissive) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 4 — pydantic, typing-extensions, motor, pymongo |
| Maintenance | actively maintained — 202 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 111,772/month — #12,399 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: odmantic-1.1.0-py3-none-any.whl
Keywords: mongodb, asyncio, types, pydantic, motor
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
beanieBeanie is an asynchronous Python…
permissive · top 5,000 on PyPI
pydantic-mongoProvides a Repository pattern for MongoDB with…
permissive · top 15,000 on PyPI
mongoengineMongoEngine provides an Object-Document Mapper…
permissive · top 5,000 on PyPI
maggmaMaggma provides a unified interface for…
unclear · top 15,000 on PyPI
pymongoPyMongo is the official MongoDB Python driver,…
permissive · top 1,000 on PyPI
Flask-PyMongoFlask-PyMongo integrates MongoDB database…
permissive · top 15,000 on PyPI
mongomock-motorProvides an async mock client for MongoDB that…
permissive · top 5,000 on PyPI
motorMotor provides a non-blocking MongoDB driver…
permissive · top 5,000 on PyPI
pymongo_inmemoryProvides an in-memory MongoDB instance for…
permissive · top 15,000 on PyPI
ormarAn async ORM for Python that unifies database…
permissive · top 15,000 on PyPI