When using Beanie each database collection has a corresponding
Document that is used to interact with that collection. In addition to retrieving data, Beanie allows you to add, update, or delete documents from the collection as well.
Beanie saves you time by removing boiler-plate code and it helps you focus on the parts of your app that actually matter.
Data and schema migrations are supported by Beanie out of the box.
pip install beanie
poetry add beanie
from typing import Optional, List import motor from beanie import Document, init_beanie from pydantic import BaseModel class Tag(BaseModel): name: str color: str class Note(Document): title: str text: Optional[str] tag_list: List[Tag] =  async def main(): # Crete Motor client client = motor.motor_asyncio.AsyncIOMotorClient( "mongodb://user:[email protected]:27017" ) # Init beanie with the Note document class await init_beanie(database=client.db_name, document_models=[Note]) # Get all the notes all_notes = await Note.find_all().to_list()
- Tutorial - Migrations usage examples
- FastAPI Demo - Beanie and FastAPI collaboration demonstration. CRUD and Aggregation.
- Indexes Demo - Regular and Geo Indexes usage example wrapped to a microservice.
- Announcing Beanie - MongoDB ODM
- Build a Cocktail API with Beanie and MongoDB
- MongoDB indexes with Beanie
- Beanie Projections. Reducing network and database load.
- GitHub - GitHub page of the project
- Changelog - list of all the valuable changes
- Discord - ask your questions, share ideas or just say
Supported by JetBrains