KV¶
-
class
binp.kv.
KV
(namespace='default', db=None)[source]¶ Basic Key-Value storage with namespace.
By default - ‘default’ namespace used. All values are serialized to JSON by standard JSON module or in case value is subclass of pydantic BaseMode - by pydantic
.json()
.- Example
from binp import BINP binp = BINP() async def save_something(): # save multiple values to storage await binp.kv.set(name="reddec", repo="binp", year=2020) # get single value name = await binp.kv.get('name') assert name == 'reddec'
There is some optimization for saving/loading Pydantic classes when class name itself a key.
- Example
from binp import BINP from pydantic.main import BaseModel binp = BINP() class Author(BaseModel): name: str repo: str year: int async def save_something(): value = Author(name="reddec", repo="binp", year=2020) # save class with key name equal to fully-qualified class name await binp.kv.save(value) # restore saved_value = await binp.kv.load(Author) assert value == saved_value
-
async
get
(name)[source]¶ Get save value by name.
- Return type
Union
[str
,int
,float
,bool
,dict
,None
]