Filesystem KV
The FilesystemKV
stores items as files in a (nested) directory.
Example
from kv import KV, FilesystemKV
kv = KV.of('file://path/to/folder', type=dict) # -> FilesystemKV
await kv.insert('key1', {'value': 1})
await kv.insert('nested/key2', {'value': 2})
await kv.insert('key3', {'value': 3})
This will yield:
File Extensions
By default, the extension is determined by the data type:
KV.of('file://path/to/folder', type=dict) # -> .json
KV.of('file://path/to/folder', type=str) # -> .txt
KV.of('file://path/to/folder', type=bytes) # -> (no extension)
Or you can specify it manually:
Datatypes
str|bytes
: written as-isdict|list|dataclass|etc
: validated as JSON usingpydantic
Prefixing
The filesystem backend supports prefixing by creating nested directories.
All of these are equivalent: