lightodm - Lightweight MongoDB ODMï
lightodm is a minimalistic MongoDB ODM (Object-Document Mapper) for Python, designed as a lightweight alternative to Beanie.
Why lightodm?ï
ðŠķ Lightweight: ~500 lines of code vs 5000+ in Beanie
ð Dual Support: Both sync (PyMongo) and async (Motor) operations
ðŊ Pydantic v2 Native: Built for Pydantic v2 from the ground up
ð Flexible Connection: Bring Your Own Connection (BYOC) pattern
ðĶ Direct Access: Direct PyMongo/Motor API access, no abstraction layers
ðĄ Type Safe: Full type hints support
â Well Tested: Comprehensive test coverage
Quick Startï
Installation:
pip install lightodm
Basic Usage:
from lightodm import MongoBaseModel, connect
# Optional: Use built-in connection manager
connect(
url="mongodb://localhost:27017",
username="user",
password="pass",
db_name="mydb"
)
# Define your model
class User(MongoBaseModel):
class Settings:
name = "users" # Collection name
name: str
email: str
age: int
# Sync operations
user = User(name="John", email="john@example.com", age=30)
user.save()
found_user = User.get(user.id)
# Async operations
await user.asave()
found_user = await User.aget(user.id)