Registry / database / odmantic

odmantic

JSON →
library1.1.0pypypi✓ verified 91d ago

ODMantic is an async ODM (Object Document Mapper) for MongoDB, based on Pydantic and Motor. It leverages Python type hints to define models and provides a clean asynchronous API. Current version is 1.1.0, with active development and quarterly releases.

pip install odmantic
INSTALL
IMPORT
SIG · ODMANTIC
O
odmantic
databasepythonv1.1.0
Install
4.4s avg
Import
852ms
Disk
37MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v1.1.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
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.872s · 36.8MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 4.4s · import 0.832s · 38MB
37MB installed
● package 37MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Model
✓ from odmantic import Model
✗ from pydantic import BaseModel
ODMantic models must inherit from odmantic.Model, not BaseModel, to enable MongoDB persistence.
Field
✓ from odmantic import Field
✗ from pydantic import Field
Use ODMantic's Field for model fields; it wraps Pydantic's Field but adds ODM-specific features.
ObjectId
✓ from odmantic import ObjectId
✗ from bson import ObjectId
ODMantic provides its own version of ObjectId that integrates with its model system.

Creates a Player model, saves an instance to MongoDB, and retrieves it.

import asyncio from odmantic import AIOEngine, Model, Field from motor.motor_asyncio import AsyncIOMotorClient class Player(Model): name: str level: int = Field(default=1) async def run(): client = AsyncIOMotorClient(os.environ.get('MONGODB_URI', 'mongodb://localhost:27017')) engine = AIOEngine(motor_client=client, database='test') player = Player(name='Alice', level=5) await engine.save(player) print(f"Saved player with id: {player.id}") found = await engine.find_one(Player, Player.name == 'Alice') print(found) client.close() asyncio.run(run())
Debug
Known issues
breakingODMantic 1.0.0 dropped support for Pydantic v1 and Python 3.7. Models defined with Pydantic v1 syntax will break.
fix
Upgrade models to Pydantic v2 syntax (e.g., use `Field` from odmantic, update validators).
affects: <1.0.0
gotchaDo not mix ODMantic's `Field` with Pydantic's `Field`. Using `from pydantic import Field` inside an ODMantic model can cause validation issues.
fix
Always import Field from odmantic: `from odmantic import Field`.
affects: all
gotchaODMantic models are async-only. Calling `save()` without `await` will not persist data and may return a coroutine.
fix
Always use `await` with engine methods like `save`, `find`, `find_one`, `delete`, etc.
affects: all
Errors
Common errors & fixes
AttributeError: 'AIOEngine' object has no attribute 'save'
In older versions (<0.7), 'save' was a method on the Engine instance. After refactoring, it's still a method, but the error may occur if a typo or using a wrong object.
fix
Ensure you're using the AIOEngine correctly: `await engine.save(instance)`. Verify you have installed ODMantic >=0.7.
pydantic.errors.PydanticUserError: Cannot use `Field` from pydantic inside an ODMantic model
Using `from pydantic import Field` instead of `from odmantic import Field`.
fix
Change the import to: `from odmantic import Field`
TypeError: 'coroutine' object does not support item assignment
Forgetting to await an async engine call (e.g., `engine.find_one(...)` returns a coroutine, not the result).
fix
Add `await` before the engine call: `player = await engine.find_one(...)`
Upgrade
Version history
1.1.0latest on PyPI · released Jan 24, 2026
Audit
Dependencies
motorrequiredAsync MongoDB driver; required at runtime
pydanticrequiredData validation and settings management; required at runtime
Agent activity
8 hits · last 30 days
node
8
Resources
odmantic — pip install odmantic · libregistry