Skip to main content

Asynchronous Python ODM for Redis

Project description

Beanis

pypi

📢 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:

Beanie

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

beanis-0.0.5.tar.gz (38.8 kB view details)

Uploaded Source

Built Distribution

beanis-0.0.5-py3-none-any.whl (56.3 kB view details)

Uploaded Python 3

File details

Details for the file beanis-0.0.5.tar.gz.

File metadata

  • Download URL: beanis-0.0.5.tar.gz
  • Upload date:
  • Size: 38.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.10.14

File hashes

Hashes for beanis-0.0.5.tar.gz
Algorithm Hash digest
SHA256 47e706ec43fdab5485d9803c3c3d80c1f314ac4caa8ac6d5a6954b090f2acc38
MD5 adc7e82e599ba674cbf76a507770a4c5
BLAKE2b-256 6ef72fddfb9bf0d45185f4b3348b4c90c248b73d99e87509d6b9cd62a967fb7e

See more details on using hashes here.

File details

Details for the file beanis-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: beanis-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 56.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.10.14

File hashes

Hashes for beanis-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 6299be1b16036b1f01d4dfd0efac1f8c6f67f6649e869e8d7ce3b2eefae664ee
MD5 3da4a5d8dfe2e6ed1f7a434c8c056290
BLAKE2b-256 9d680aa0fbeb5182f72c5f137383f8b11645d6990d3108730a50ad2125aa21c3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page