Interested in using MongoDB for my DB - Looking for Async ODM Solution for Python

Hi there! As the title suggests, I’m looking for an Asynchronous ODM abstraction for use specifically with FastAPI. My language of choice is Python.

So far I’ve seen Beanie and ODMantic but wanted to go straight to the source and get advice from experienced MongoDB devs. What do you all think? Anything else to know before diving in?

Welcome to the MongoDB Community Forums @Anthony_Polyak !

Beanie and ODMantic both build on similar dependencies:

  • Motor - officially supported asynchronous Python driver for MongoDB
  • Pydantic - data validation and settings management using Python type annotations

I’m also aware of μMongo: sync/async ODM, which predates Beanie and ODMantic by 4 or 5 years and uses Marshmallow for serialisation instead of Pymantic. Beanie is the newest of the ODMs mentioned here – the initial release was just under a year ago, with 40+ releases since then.

There may be other Python async ODMs, but these are the ones I see most commonly mentioned in community discussion (which is far less frequently than folks using the Motor async driver directly in my experience).

If you are just getting started with MongoDB I would consider using Motor directly. ODMs try to improve developer experience/convenience but there is a performance and troubleshooting tradeoff given extra layers of abstraction and potential overhead.

Any of the mentioned libraries will work with FastAPI, including using Motor directly: Getting Started with MongoDB and FastAPI.

Regards,
Stennie

2 Likes