Asynchronous Python ODM for MongoDB with modern Pydantic-based document mapping
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Schema migration tools for iterative and free-form data migrations with batch processing support.
def iterative_migration(
document_models: List[Type[Document]],
batch_size: int = 1000
):
"""Decorator for creating iterative data migrations with batching."""
...def free_fall_migration(document_models: List[Type[Document]]):
"""Decorator for creating free-form migration functions."""
...from beanie import Document, iterative_migration, free_fall_migration
class User(Document):
name: str
email: str
class Settings:
collection = "users"
@iterative_migration(document_models=[User], batch_size=100)
async def migrate_user_data():
"""Add default values for new field."""
async for user in User.find({"active": {"$exists": False}}):
user.active = True
await user.save()
@free_fall_migration(document_models=[User])
async def complex_migration():
"""Complex data transformation."""
# Custom migration logic
await User.find({"old_field": {"$exists": True}}).update({"$unset": {"old_field": ""}})Install with Tessl CLI
npx tessl i tessl/pypi-beanie