![pypi](https://img.shields.io/pypi/v/bunnet.svg)
![Bunnet](https://github.com/roman-right/bunnet/raw/main/docs/assets/1.png)
The logo is generated by WOMBO Dream
Overview
Bunnet - is a Python object-document mapper (ODM) for MongoDB. It is a synchronous fork of Beanie ODM.
When using Bunnet each database collection has a corresponding Document
that
is used to interact with that collection. In addition to retrieving data,
Bunnet allows you to add, update, or delete documents from the collection as
well.
Bunnet saves you time by removing boilerplate code, and it helps you focus on
the parts of your app that actually matter.
Installation
PIP
pip install bunnet
Poetry
poetry add bunnet
Example
from typing import Optional
from pymongo import MongoClient
from pydantic import BaseModel
from bunnet import Document, Indexed, init_bunnet
class Category(BaseModel):
name: str
description: str
class Product(Document):
name: str
description: Optional[str] = None
price: Indexed(float)
category: Category
client = MongoClient("mongodb://user:pass@host:27017")
init_bunnet(database=client.db_name, document_models=[Product])
chocolate = Category(name="Chocolate", description="A preparation of roasted and ground cacao seeds.")
tonybar = Product(name="Tony's", price=5.95, category=chocolate)
tonybar.insert()
product = Product.find_one(Product.price < 10).run()
product.set({Product.name:"Gold bar"})
Links
Documentation
- Doc - Tutorial, API documentation, and development guidelines.
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](https://raw.githubusercontent.com/roman-right/beanie/main/assets/logo/jetbrains.svg)