Apache License 2.0

项目介绍

BeanieODM/beanie 是一个托管在 GitHub 上的开源项目,主要使用 Python 编写,采用 Apache License 2.0 许可证,目前获得 2.7k 个 Star、310 次 Fork。

仓库全名
BeanieODM/beanie
开源许可证
Apache License 2.0
Star 数
2.7k
Fork 数
310
未关闭 Issue
69

README 摘要

[!IMPORTANT] We are actively working on Beanie v3. This is a major release - it brings multiple significant new features and improvements across the whole library. It's a substantial amount of work, and it has most of our attention right now, so reviews and responses on open pull requests and issues may be slower than usual. Thanks for your patience - v3 will be worth the wait. Overview Beanie - is an asynchronous…

完整内容见 GitHub 原始 README 或本页 。

常见问题

beanie 用什么语言开发?

主要使用 Python 编写,采用 Apache License 2.0 许可证,目前有 2.7k 个 Star。

beanie 可以免费商用吗?

仓库采用 Apache License 2.0 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 beanie 的源码?

可以直接克隆仓库:git clone https://github.com/BeanieODM/beanie.git,默认分支为 main;安装与运行步骤见仓库 README。

beanie 最近还在维护吗?

仓库最近一次更新为 5 天前,当前有 69 个未关闭 Issue;Star 数为 2.7k,可作为社区活跃度的参考。

简要分析

热度分
3347
价值分
1716
活跃状态
活跃

语言占比

Python
Shell

Release

README

Beanie

shields badge pypi pre-commit.ci status

[!IMPORTANT] We are actively working on Beanie v3. This is a major release - it brings multiple significant new features and improvements across the whole library. It’s a substantial amount of work, and it has most of our attention right now, so reviews and responses on open pull requests and issues may be slower than usual. Thanks for your patience - v3 will be worth the wait.

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!!

评论

暂无评论