beanie


Namebeanie JSON
Version 1.25.0 PyPI version JSON
download
home_pageNone
SummaryAsynchronous Python ODM for MongoDB
upload_time2024-01-25 05:28:59
maintainerNone
docs_urlNone
authorNone
requires_python>=3.7,<4.0
licenseNone
keywords mongodb odm orm pydantic mongo async python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![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)

[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/G2G0PS833)

## 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
```
## 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/29mMrEBvr4)** - 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": ">=3.7,<4.0",
    "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/c5/17/c37e5728bf99f9a0955b064975ca544f3a1a3eb8b170a4db1553e469d423/beanie-1.25.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[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/G2G0PS833)\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## 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/29mMrEBvr4)** - 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.25.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": "da2b32b65d5c2327c8edb849b66dc7c69b8a753aadee411c7f1568a8b57f2bc2",
                "md5": "0d63d0d51388bfa3ea50f9fbc7774f3a",
                "sha256": "4436ac740718ccd62b21576778679ac972359fce2938557890c576adbbf5e244"
            },
            "downloads": -1,
            "filename": "beanie-1.25.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0d63d0d51388bfa3ea50f9fbc7774f3a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7,<4.0",
            "size": 81219,
            "upload_time": "2024-01-25T05:28:56",
            "upload_time_iso_8601": "2024-01-25T05:28:56.008522Z",
            "url": "https://files.pythonhosted.org/packages/da/2b/32b65d5c2327c8edb849b66dc7c69b8a753aadee411c7f1568a8b57f2bc2/beanie-1.25.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "c517c37e5728bf99f9a0955b064975ca544f3a1a3eb8b170a4db1553e469d423",
                "md5": "95725e8a31f195b26c266bf177b5d72c",
                "sha256": "f153866b9ba015274102e10a397602d088fc039b705bd806cb447c898cd2979b"
            },
            "downloads": -1,
            "filename": "beanie-1.25.0.tar.gz",
            "has_sig": false,
            "md5_digest": "95725e8a31f195b26c266bf177b5d72c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7,<4.0",
            "size": 158674,
            "upload_time": "2024-01-25T05:28:59",
            "upload_time_iso_8601": "2024-01-25T05:28:59.134102Z",
            "url": "https://files.pythonhosted.org/packages/c5/17/c37e5728bf99f9a0955b064975ca544f3a1a3eb8b170a4db1553e469d423/beanie-1.25.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-25 05:28:59",
    "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"
}
        
Elapsed time: 0.17611s