Asynchronous Python ODM for Redis
Project description
Beanis
📢 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 # You can use normal types just like in pydantic
description: Optional[str] = None
price: float
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():
# Beanis uses Redis async client under the hood
client = Redis(host="localhost", port=6379, db=0, decode_responses=True)
# Initialize beanis with the Product document class
await init_beanis(database=client, document_models=[Product])
chocolate = Category(
name="Chocolate",
description="A preparation of roasted and ground cacao seeds.",
)
# Beanis documents work just like pydantic models
tonybar = Product(
id="unique_magic_id", name="Tony's", price=5.95, category=chocolate
)
# And can be inserted into the database
await tonybar.insert()
# You can find documents by their unique id
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:
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file beanis-0.0.1.tar.gz
.
File metadata
- Download URL: beanis-0.0.1.tar.gz
- Upload date:
- Size: 38.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.10.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 810ed44937fcf8b1f095f357228efbe638a313d63b5fd1d2378d2636ee31bfad |
|
MD5 | eaf7e709df60002230917c1c0da0ce92 |
|
BLAKE2b-256 | 08cc32f47ec788715490643634df42240ea1cfaa1edf3743056bf0ef9788f33a |
File details
Details for the file beanis-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: beanis-0.0.1-py3-none-any.whl
- Upload date:
- Size: 56.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.10.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b352b183cdaa3259bf95f860969f36dc185466719ba88ab388330a3442cd972 |
|
MD5 | 4c8b05ccb781e718c6cb8514d58ba18d |
|
BLAKE2b-256 | 56c3503dc9d19c1a142e65cb7f34d5e39c359cc56f90c9e5cd60d94b6da50035 |