Volver al ranking

BeanieODM/beanie

Pythonbeanie-odm.dev

Asynchronous Python ODM for MongoDB

mongodbpydanticasynchronousasynciomotorbeaniemongoasyncpythonormodmpymongo
Crecimiento de estrellas
Estrellas
2.7k
Forks
300
Crecimiento semanal
Issues
70
1k2k
mar 2021dic 2022oct 2024jul 2026
ArtefactosPyPIpip install beanie
README

Beanie

shields badge pypi pre-commit.ci status

📢 Important Update 📢

We are excited to announce that Beanie is transitioning from solo development to a team-based approach! This move will help us enhance the project with new features and more collaborative development.

At this moment we are establishing a board of members that will decide all the future steps of the project. We are looking for contributors and maintainers to join the board.

Join Us

If you are interested in contributing or want to stay updated, please join our Discord channel. We're looking forward to your ideas and contributions!

Join our Discord

Let’s make Beanie better, together!

Overview

Beanie - is an asynchronous Python object-document mapper (ODM) for MongoDB. Data models are based on Pydantic.

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 boilerplate 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.

There is a synchronous version of Beanie ODM - Bunnet

Installation

PIP

pip install beanie

Poetry

poetry add beanie

For more installation options (eg: aws, gcp, srv ...) you can look in the getting started

Example

import asyncio
from typing import Optional

from pymongo import AsyncMongoClient
from pydantic import BaseModel

from beanie import Document, Indexed, init_beanie


class Category(BaseModel):
    name: str
    description: str


class Product(Document):
    name: str                          # You can use normal types just like in pydantic
    description: Optional[str] = None
    price: Indexed(float)              # You can also specify that a field should correspond to an index
    category: Category                 # You can include pydantic models as well


# This is an asynchronous example, so we will access it from an async function
async def example():
    # Beanie uses PyMongo async client under the hood
    client = AsyncMongoClient("mongodb://user:pass@host:27017")

    # Initialize beanie with the Product document class
    await init_beanie(database=client.db_name, document_models=[Product])

    chocolate = Category(name="Chocolate", description="A preparation of roasted and ground cacao seeds.")
    # Beanie documents work just like pydantic models
    tonybar = Product(name="Tony's", price=5.95, category=chocolate)
    # And can be inserted into the database
    await tonybar.insert() 
    
    # You can find documents with pythonic syntax
    product = await Product.find_one(Product.price < 10)
    
    # And update them
    await product.set({Product.name:"Gold bar"})


if __name__ == "__main__":
    asyncio.run(example())

Documentation

  • Doc - Tutorial, API documentation, and development guidelines.

Example Projects

Articles

Resources

  • GitHub - GitHub page of the project
  • Changelog - list of all the valuable changes
  • Discord - ask your questions, share ideas or just say Hello!!

Supported by JetBrains

JetBrains

Repositorios relacionados
macrozheng/mall

mall项目是一套电商系统,包括前台商城系统及后台管理系统,基于Spring Boot+MyBatis实现,采用Docker容器化部署。 前台商城系统包含首页门户、商品推荐、商品搜索、商品展示、购物车、订单流程、会员中心、客户服务、帮助中心等模块。 后台管理系统包含商品管理、订单管理、会员管理、促销管理、运营管理、内容管理、统计报表、财务管理、权限管理、设置等模块。

JavaMavenApache License 2.0spring-bootspring-security
macrozheng.com/admin/
84.3k29.8k
netdata/netdata

The fastest path to AI-powered full stack observability, even for lean teams.

GoGo ModulesGNU General Public License v3.0monitoringdocker
netdata.cloud
79.8k6.5k
Asabeneh/30-Days-Of-Python

The 30 Days of Python programming challenge is a step-by-step guide to learn the Python programming language in 30 days. This challenge may take more than 100 days. Follow your own pace. These videos may help too: https://www.youtube.com/channel/UC7PNRuno1rzYPb1xLa4yktw

PythonPyPI30-days-of-pythonpython
68.8k12.8k
prisma/prisma

Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB

TypeScriptnpmApache License 2.0prismaorm
prisma.io
47.4k2.4k
meteor/meteor

Meteor, the JavaScript App Platform

JavaScriptnpmOtherjavascriptmeteor
meteor.com
44.8k5.2k
payloadcms/payload

Payload is the open-source, fullstack Next.js framework, giving you instant backend superpowers. Get a full TypeScript backend and admin panel instantly. Use Payload as a headless CMS or for building powerful applications.

TypeScriptnpmMIT Licenseheadless-cmscms
payloadcms.com
43.7k4k
0voice/interview_internal_reference

2025年最新总结,阿里,腾讯,百度,美团,头条等技术面试题目,以及答案,专家出题人分析汇总。

PythonPyPInetworkredis
37.2k9.4k
mouredev/Hello-Python

Curso para aprender el lenguaje de programación Python desde cero y para principiantes. 100 clases, 44 horas en vídeo, código, proyectos y grupo de chat. Fundamentos, frontend, backend, testing, IA...

PythonPyPIApache License 2.0fastapimongodb
mouredev.link/python
36.5k2.3k
Dokploy/dokploy

Open Source Alternative to Vercel, Netlify and Heroku.

TypeScriptnpmOtherdeploymentself-hosted
dokploy.com
36k2.8k
hasura/graphql-engine

Blazing fast, instant realtime GraphQL APIs on all your data with fine grained access control, also trigger webhooks on database events.

TypeScriptnpmApache License 2.0graphqlgraphql-server
hasura.io
32k2.9k
ityouknow/spring-boot-examples

about learning Spring Boot via examples. Spring Boot 教程、技术栈示例代码,快速简单上手教程。

JavaMavenspring-bootspring-data-jpa
ityouknow.com/spring-boot.html
30.5k12.2k
mongodb/mongo

The MongoDB Database

C++Otherc-plus-plusdatabase
mongodb.com
28.5k5.8k