Skip to main content

Simple redis storage for pydantic objects with an interface of the MutableMapping.

Project description

redantic

License: MIT

Simple redis storage for pydantic objects with an interface of the MutableMapping.

Examples

from redantic import RedisDict
from pydantic import BaseModel
from redis import Redis

class Car(BaseModel):
    price: float
    model: str

CarId = int

client = Redis()
d = RedisDict[CarId, Car](client=client, name='car_collection', key_type=CarId, value_type=Car)
d[1] = Car(price=100.5, model='a')
d[2] = Car(price=200, model='b')

print(len(d))
for i in d:
    print(d[i])

You can also use pydantic object as a key.

class CarId(BaseModel):
    id: int
    type: str

d[CarId(id=1, type='some_type')] = Car(price=100.5, model='a')

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

redantic-0.1.1.tar.gz (3.0 kB view hashes)

Uploaded Source

Built Distribution

redantic-0.1.1-py3-none-any.whl (3.2 kB view hashes)

Uploaded Python 3

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