📢 Work in Progress Disclaimer 📢
Beanis is currently a work in progress. While the core functionality is being actively developed, some features may still be in the testing phase. We appreciate your understanding and welcome any feedback or contributions to help us improve the project.
Overview
Beanis is an asynchronous Python object-document mapper (ODM) for Redis, designed to simplify database interactions using data models based on Pydantic.
With Beanis, each Redis key is represented by a Document
, allowing for easy interaction with that key. This includes retrieving, adding, updating, and deleting documents from the key, all while maintaining the simplicity and power of Pydantic models.
Beanis aims to save you time by eliminating boilerplate code, allowing you to focus on the crucial parts of your application.
Installation
PIP
pip install beanis
Poetry
poetry add beanis
Example
import asyncio
from typing import Optional
from redis import Redis
from pydantic import BaseModel
from beanis import Document, init_beanis
class Category(BaseModel):
name: str
description: str
class Product(Document):
name: str
description: Optional[str] = None
price: float
category: Category
async def example():
client = Redis(host="localhost", port=6379, db=0, decode_responses=True)
await init_beanis(database=client, document_models=[Product])
chocolate = Category(
name="Chocolate",
description="A preparation of roasted and ground cacao seeds.",
)
tonybar = Product(
id="unique_magic_id", name="Tony's", price=5.95, category=chocolate
)
await tonybar.insert()
product = await Product.find("unique_magic_id")
print(product)
if __name__ == "__main__":
asyncio.run(example())
Thanks to the amazing team behind Beanie, Beanis brings similar powerful ODM capabilities to Redis, making it easier than ever to manage your Redis database with Python. Please check them out: