Library / SDK
BeanieODM/beanie avatar
BeanieODM/beanie

Beanie: an async Python ODM for MongoDB built on Pydantic

Asynchronous Python ODM for MongoDB

2,711 stars309 forksPythonApache-2.0

At a glance

What is it?
Beanie maps MongoDB collections to Pydantic models and drives them through the PyMongo async client. It suits asyncio services that already think in Pydantic types, and it stops being the right tool the moment you need joins or a relational schema.
Who is it for?
Adopt Beanie if your service is already asyncio and your data is document-shaped: the Document class plus init_beanie is a small amount of code for a full CRUD and query layer. Do not adopt it if you need cross-collection joins, a relational schema, or a synchronous codebase, where Bunnet is the project's own answer.
Can I use it commercially?
Yes. Apache-2.0 is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository received new commits within the last day.
What is it written in?
Mainly Python, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 23, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • BeanieODM/beanie2,711 ★ · +9
Star history
Repository2026-09-302026-11-23
BeanieODM/beanie2.7k2.7k

9 Stars in the last 54 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

The problem Beanie solves for asyncio services on MongoDB

MongoDB's Python driver returns dictionaries. That is fine for a script and painful for an application: every read hands you a plain dict, every write takes one, and nothing checks that the fields you set actually exist on the collection. Beanie's answer is to make each collection correspond to a Document class, so the shape of your data lives in Python types rather than in your head. The README states this directly: "each database collection has a corresponding Document that is used to interact with that collection." The audience is narrow and specific. You need an async application, most often a FastAPI service, and you need MongoDB or a MongoDB-compatible server. If you are writing synchronous code, Beanie is the wrong half of the project; the README points to Bunnet as the synchronous version. The value proposition is boilerplate removal, not a new query language. Beanie does not hide MongoDB from you, it types the boundary between your Python objects and the driver.

Documents, Pydantic models and the PyMongo async client underneath

The mechanism has three layers. At the bottom sits the PyMongo async client, which the README names explicitly: "Beanie uses PyMongo async client under the hood." Above it, Beanie holds a registry of Document classes, populated when you call init_beanie with a database handle and a list of models. Above that, your Document subclasses are ordinary Pydantic models with database behaviour attached. Fields are declared with normal Python types, and a field wrapped in Indexed is marked as corresponding to an index. Nested Pydantic models are allowed as field types, so a Product can embed a Category without a second collection. Queries are built from class attributes rather than raw filter dictionaries: Product.find_one(Product.price < 10) compiles the comparison into a MongoDB filter. The same class attributes appear in update calls, as in product.set({Product.name: "Gold bar"}), which means a renamed field breaks at the call site instead of silently writing to a key that no longer exists. The README also states that data and schema migrations are supported out of the box, though the README itself does not walk through a migration; that detail lives in the linked documentation.

Installing Beanie and inserting your first document

The README gives two install paths, pip and Poetry. Either produces the same package, and the optional dependency extras (the README lists aws, gcp and srv among them) are covered in the getting started documentation rather than the front page.

bash
pip install beanie

With the package installed, the smallest useful program defines a Document, opens a client, and calls init_beanie before touching any data. The example below follows the README's own example, trimmed to the parts that matter for a first run. Note that the client comes from pymongo, not from beanie.

python
import asyncio
from pymongo import AsyncMongoClient
from beanie import Document, Indexed, init_beanie

class Product(Document):
    name: str
    price: Indexed(float)

async def main():
    client = AsyncMongoClient("mongodb://user:pass@host:27017")
    await init_beanie(database=client.db_name, document_models=[Product])
    await Product(name="Tony's", price=5.95).insert()

asyncio.run(main())

After this runs, the collection backing Product contains one document. From there the README shows the two calls you will use most: Product.find_one(Product.price < 10) to read and await product.set({Product.name: "Gold bar"}) to update. The insert, find and update calls are all awaited, which is the point of the whole design: nothing blocks the event loop while MongoDB is answering.

Where Beanie is the wrong tool

Beanie inherits MongoDB's data model, and that is the limitation that matters. There are no joins across collections in the sense a relational developer expects, so if your domain is naturally normalized, you will either embed documents and duplicate data or issue several queries and stitch results together yourself. Beanie will not stop you, but it will not help either. The second constraint is the dependency surface. The package requires Python 3.10 through 3.13 and PyMongo 4.11.0 or later, with 4.15.0 explicitly excluded. Those are real boundaries: a service pinned to Python 3.9, or to an older PyMongo, cannot use this release. Third, the async model is not optional. Every data call is awaited, so a synchronous codebase would have to be rewritten around an event loop before Beanie earns its place. Finally, the README advertises migrations but does not show one. If you need to know what a migration does to existing documents, or how to reverse it, the front page is silent and you will be reading the documentation site instead.

Beanie against the raw driver and against Bunnet

The honest alternative is not another ODM; it is the PyMongo async client on its own. Using the driver directly means you write filter dictionaries by hand, you get dicts back, and you validate the shape of your data yourself, with Pydantic or without it. The difference in approach is where the type lives. With the driver, the collection's schema is a convention shared by your code and your database, enforced nowhere. With Beanie, the schema is a class, and every query and update is expressed through that class's attributes, so a typo becomes an error rather than a query that quietly matches nothing. The cost is a layer of abstraction over the driver, and a smaller community than PyMongo's. The project's own second alternative is Bunnet, described in the README as the synchronous version of Beanie. Same modelling idea, no event loop. If your application is a WSGI service, Bunnet is the more direct fit; adopting Beanie there means adding asyncio to a codebase that was not built for it.

Maintenance, versioning and the Apache-2.0 licence

The repository is not archived, and the last push was on 2026-09-21. Release 2.2.0 landed on 2026-08-31, preceded by 2.1.0 on 2026-03-27 and 2.0.1 on 2025-11-20. That cadence is worth reading before you pin a version: the 2.x line has moved within a year, and the project is past its 1.0 query builder era that the linked articles describe. The declared dependency ranges are the practical upgrade constraint. Pydantic is held below 3.0 and PyMongo below 5.0, so a major bump in either library will require a Beanie release before you can follow it. PyMongo 4.15.0 is excluded outright, which suggests a known incompatibility rather than a preference. The licence is Apache-2.0, a permissive licence that permits commercial use and modification; the LICENSE file is the authoritative text, and nothing here is legal advice. One more cost to budget: the README does not document rollback for migrations, so a team that runs migrations in production should confirm the reversal story in the documentation before relying on it.

Editorial conclusion

Adopt Beanie if your service is already asyncio and your data is document-shaped: the Document class plus init_beanie is a small amount of code for a full CRUD and query layer. Do not adopt it if you need cross-collection joins, a relational schema, or a synchronous codebase, where Bunnet is the project's own answer. Before committing, verify that your Python and PyMongo versions sit inside the declared ranges, and read the migration documentation, because the README does not document rollback behaviour.

Frequently asked questions

What is Beanie ODM?

Beanie is an asynchronous Python object-document mapper for MongoDB, with data models based on Pydantic. Each collection has a corresponding Document class that you use to add, update, delete and query documents.

How do I install Beanie?

The README gives two commands: pip install beanie, or poetry add beanie. Optional dependency extras such as aws, gcp and srv are documented in the getting started guide rather than the README front page.

How do you use Beanie with MongoDB?

You create a PyMongo async client, then call await init_beanie with the database and a list of document models before using any of them. After that, documents are inserted, found and updated with awaited calls such as insert(), find_one() and set().

Does Beanie have a synchronous version?

Yes. The README states that Bunnet is the synchronous version of Beanie ODM, pointing to its own repository for synchronous codebases.

Which Python and PyMongo versions does Beanie require?

The package metadata requires Python 3.10 up to but not including 3.14, and PyMongo 4.11.0 or later with version 4.15.0 explicitly excluded. Pydantic must be at least 2.4 and below 3.0.

Official sources

  1. BeanieODM/beanie on GitHub
  2. License: Apache-2.0
  3. Project website
  4. README
  5. Releases
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/beanieodm-beanie.svg)](https://hysenlabs.com/projects/beanieodm-beanie)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/beanieodm-beanie.svg)](https://hysenlabs.com/projects/beanieodm-beanie)

Was this useful?