[![Beanie](https://raw.githubusercontent.com/roman-right/beanie/main/assets/logo/white_bg.svg)](https://github.com/roman-right/beanie)
[![shields badge](https://shields.io/badge/-docs-blue)](https://beanie-odm.dev)
[![pypi](https://img.shields.io/pypi/v/beanie.svg)](https://pypi.python.org/pypi/beanie)
## 📢 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](https://discord.gg/AwwTrbCASP)
Let’s make Beanie better, together!
## Overview
[Beanie](https://github.com/roman-right/beanie) - is an asynchronous Python object-document mapper (ODM) for MongoDB. Data models are based on [Pydantic](https://pydantic-docs.helpmanual.io/).
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](https://github.com/roman-right/bunnet)
## Installation
### PIP
```shell
pip install beanie
```
### Poetry
```shell
poetry add beanie
```
For more installation options (eg: `aws`, `gcp`, `srv` ...) you can look in the [getting started](./docs/getting-started.md#optional-dependencies)
## Example
```python
import asyncio
from typing import Optional
from motor.motor_asyncio import AsyncIOMotorClient
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 Motor async client under the hood
client = AsyncIOMotorClient("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())
```
## Links
### Documentation
- **[Doc](https://beanie-odm.dev/)** - Tutorial, API documentation, and development guidelines.
### Example Projects
- **[fastapi-cosmos-beanie](https://github.com/tonybaloney/ants-azure-demos/tree/master/fastapi-cosmos-beanie)** - FastAPI + Beanie ODM + Azure Cosmos Demo Application by [Anthony Shaw](https://github.com/tonybaloney)
- **[fastapi-beanie-jwt](https://github.com/flyinactor91/fastapi-beanie-jwt)** -
Sample FastAPI server with JWT auth and Beanie ODM by [Michael duPont](https://github.com/flyinactor91)
- **[Shortify](https://github.com/IHosseini083/Shortify)** - URL shortener RESTful API (FastAPI + Beanie ODM + JWT & OAuth2) by [
Iliya Hosseini](https://github.com/IHosseini083)
- **[LCCN Predictor](https://github.com/baoliay2008/lccn_predictor)** - Leetcode contest rating predictor (FastAPI + Beanie ODM + React) by [L. Bao](https://github.com/baoliay2008)
### Articles
- **[Announcing Beanie - MongoDB ODM](https://dev.to/romanright/announcing-beanie-mongodb-odm-56e)**
- **[Build a Cocktail API with Beanie and MongoDB](https://developer.mongodb.com/article/beanie-odm-fastapi-cocktails/)**
- **[MongoDB indexes with Beanie](https://dev.to/romanright/mongodb-indexes-with-beanie-43e8)**
- **[Beanie Projections. Reducing network and database load.](https://dev.to/romanright/beanie-projections-reducing-network-and-database-load-3bih)**
- **[Beanie 1.0 - Query Builder](https://dev.to/romanright/announcing-beanie-1-0-mongodb-odm-with-query-builder-4mbl)**
- **[Beanie 1.8 - Relations, Cache, Actions and more!](https://dev.to/romanright/announcing-beanie-odm-18-relations-cache-actions-and-more-24ef)**
### Resources
- **[GitHub](https://github.com/roman-right/beanie)** - GitHub page of the
project
- **[Changelog](https://beanie-odm.dev/changelog)** - list of all
the valuable changes
- **[Discord](https://discord.gg/AwwTrbCASP)** - ask your questions, share
ideas or just say `Hello!!`
----
Supported by [JetBrains](https://jb.gg/OpenSource)
[![JetBrains](https://raw.githubusercontent.com/roman-right/beanie/main/assets/logo/jetbrains.svg)](https://jb.gg/OpenSource)
Raw data
{
"_id": null,
"home_page": null,
"name": "beanie",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.8",
"maintainer_email": null,
"keywords": "mongodb, odm, orm, pydantic, mongo, async, python",
"author": null,
"author_email": "Roman Right <roman-right@protonmail.com>",
"download_url": "https://files.pythonhosted.org/packages/dc/12/9f7b8600eb53b81dffd121d2ea5d6c3d9283f384926596c2212baf6ddd3a/beanie-1.28.0.tar.gz",
"platform": null,
"description": "[![Beanie](https://raw.githubusercontent.com/roman-right/beanie/main/assets/logo/white_bg.svg)](https://github.com/roman-right/beanie)\n\n[![shields badge](https://shields.io/badge/-docs-blue)](https://beanie-odm.dev)\n[![pypi](https://img.shields.io/pypi/v/beanie.svg)](https://pypi.python.org/pypi/beanie)\n\n## \ud83d\udce2 Important Update \ud83d\udce2\n\nWe 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.\n\nAt 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.\n\n### Join Us\nIf you are interested in contributing or want to stay updated, please join our Discord channel. We're looking forward to your ideas and contributions!\n\n[Join our Discord](https://discord.gg/AwwTrbCASP)\n\nLet\u2019s make Beanie better, together!\n\n## Overview\n\n[Beanie](https://github.com/roman-right/beanie) - is an asynchronous Python object-document mapper (ODM) for MongoDB. Data models are based on [Pydantic](https://pydantic-docs.helpmanual.io/).\n\nWhen using Beanie each database collection has a corresponding `Document` that\nis used to interact with that collection. In addition to retrieving data,\nBeanie allows you to add, update, or delete documents from the collection as\nwell.\n\nBeanie saves you time by removing boilerplate code, and it helps you focus on\nthe parts of your app that actually matter.\n\nData and schema migrations are supported by Beanie out of the box.\n\nThere is a synchronous version of Beanie ODM - [Bunnet](https://github.com/roman-right/bunnet)\n\n## Installation\n\n### PIP\n\n```shell\npip install beanie\n```\n\n### Poetry\n\n```shell\npoetry add beanie\n```\n\nFor more installation options (eg: `aws`, `gcp`, `srv` ...) you can look in the [getting started](./docs/getting-started.md#optional-dependencies)\n\n## Example\n\n```python\nimport asyncio\nfrom typing import Optional\n\nfrom motor.motor_asyncio import AsyncIOMotorClient\nfrom pydantic import BaseModel\n\nfrom beanie import Document, Indexed, init_beanie\n\n\nclass Category(BaseModel):\n name: str\n description: str\n\n\nclass Product(Document):\n name: str # You can use normal types just like in pydantic\n description: Optional[str] = None\n price: Indexed(float) # You can also specify that a field should correspond to an index\n category: Category # You can include pydantic models as well\n\n\n# This is an asynchronous example, so we will access it from an async function\nasync def example():\n # Beanie uses Motor async client under the hood \n client = AsyncIOMotorClient(\"mongodb://user:pass@host:27017\")\n\n # Initialize beanie with the Product document class\n await init_beanie(database=client.db_name, document_models=[Product])\n\n chocolate = Category(name=\"Chocolate\", description=\"A preparation of roasted and ground cacao seeds.\")\n # Beanie documents work just like pydantic models\n tonybar = Product(name=\"Tony's\", price=5.95, category=chocolate)\n # And can be inserted into the database\n await tonybar.insert() \n \n # You can find documents with pythonic syntax\n product = await Product.find_one(Product.price < 10)\n \n # And update them\n await product.set({Product.name:\"Gold bar\"})\n\n\nif __name__ == \"__main__\":\n asyncio.run(example())\n```\n\n## Links\n\n### Documentation\n\n- **[Doc](https://beanie-odm.dev/)** - Tutorial, API documentation, and development guidelines.\n\n### Example Projects\n\n- **[fastapi-cosmos-beanie](https://github.com/tonybaloney/ants-azure-demos/tree/master/fastapi-cosmos-beanie)** - FastAPI + Beanie ODM + Azure Cosmos Demo Application by [Anthony Shaw](https://github.com/tonybaloney)\n- **[fastapi-beanie-jwt](https://github.com/flyinactor91/fastapi-beanie-jwt)** - \n Sample FastAPI server with JWT auth and Beanie ODM by [Michael duPont](https://github.com/flyinactor91)\n- **[Shortify](https://github.com/IHosseini083/Shortify)** - URL shortener RESTful API (FastAPI + Beanie ODM + JWT & OAuth2) by [\nIliya Hosseini](https://github.com/IHosseini083)\n- **[LCCN Predictor](https://github.com/baoliay2008/lccn_predictor)** - Leetcode contest rating predictor (FastAPI + Beanie ODM + React) by [L. Bao](https://github.com/baoliay2008)\n\n### Articles\n\n- **[Announcing Beanie - MongoDB ODM](https://dev.to/romanright/announcing-beanie-mongodb-odm-56e)**\n- **[Build a Cocktail API with Beanie and MongoDB](https://developer.mongodb.com/article/beanie-odm-fastapi-cocktails/)**\n- **[MongoDB indexes with Beanie](https://dev.to/romanright/mongodb-indexes-with-beanie-43e8)**\n- **[Beanie Projections. Reducing network and database load.](https://dev.to/romanright/beanie-projections-reducing-network-and-database-load-3bih)**\n- **[Beanie 1.0 - Query Builder](https://dev.to/romanright/announcing-beanie-1-0-mongodb-odm-with-query-builder-4mbl)**\n- **[Beanie 1.8 - Relations, Cache, Actions and more!](https://dev.to/romanright/announcing-beanie-odm-18-relations-cache-actions-and-more-24ef)**\n\n### Resources\n\n- **[GitHub](https://github.com/roman-right/beanie)** - GitHub page of the\n project\n- **[Changelog](https://beanie-odm.dev/changelog)** - list of all\n the valuable changes\n- **[Discord](https://discord.gg/AwwTrbCASP)** - ask your questions, share\n ideas or just say `Hello!!`\n\n----\nSupported by [JetBrains](https://jb.gg/OpenSource)\n\n[![JetBrains](https://raw.githubusercontent.com/roman-right/beanie/main/assets/logo/jetbrains.svg)](https://jb.gg/OpenSource)\n",
"bugtrack_url": null,
"license": null,
"summary": "Asynchronous Python ODM for MongoDB",
"version": "1.28.0",
"project_urls": {
"homepage": "https://beanie-odm.dev",
"repository": "https://github.com/roman-right/beanie"
},
"split_keywords": [
"mongodb",
" odm",
" orm",
" pydantic",
" mongo",
" async",
" python"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "2576d06b9d07042bdfeefbf94adea4ffb09c94ed63bc1063fc2bed06d929a9f1",
"md5": "54ed5256430f7aecd1da74005303ea5d",
"sha256": "6dfc4caae2f5ea647d050a9259e222c55cfa6894ca625edf1c44c956548c2b21"
},
"downloads": -1,
"filename": "beanie-1.28.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "54ed5256430f7aecd1da74005303ea5d",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.8",
"size": 84331,
"upload_time": "2024-12-08T22:53:35",
"upload_time_iso_8601": "2024-12-08T22:53:35.462920Z",
"url": "https://files.pythonhosted.org/packages/25/76/d06b9d07042bdfeefbf94adea4ffb09c94ed63bc1063fc2bed06d929a9f1/beanie-1.28.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "dc129f7b8600eb53b81dffd121d2ea5d6c3d9283f384926596c2212baf6ddd3a",
"md5": "402655337a60c9bc909de8788335d5d4",
"sha256": "6b7a221bc3cbf00d463252ed613e54934973917d978329c5cdd2ec629a1c8559"
},
"downloads": -1,
"filename": "beanie-1.28.0.tar.gz",
"has_sig": false,
"md5_digest": "402655337a60c9bc909de8788335d5d4",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.8",
"size": 170276,
"upload_time": "2024-12-08T22:53:37",
"upload_time_iso_8601": "2024-12-08T22:53:37.758369Z",
"url": "https://files.pythonhosted.org/packages/dc/12/9f7b8600eb53b81dffd121d2ea5d6c3d9283f384926596c2212baf6ddd3a/beanie-1.28.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-08 22:53:37",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "roman-right",
"github_project": "beanie",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "beanie"
}