Key-Value DB API on the filesystem
Project description
Key-Value: Filesystem
Implementation of the
KV[T]
async Key-Value ABC, on the filesystem
pip install kv-fs
Usage
Already serialized data (str
or bytes
)
from kv.fs import FilesystemKV
data = FilesystemKV[bytes]('path/to/data')
# and then use it as you'd a KV[bytes]
Custom serialization
from kv.fs import FilesystemKV, InvalidData
from haskellian import Either, Left, Right
import json
def safe_parse(x: bytes) -> Either[InvalidData, dict]:
try:
return Right(json.loads(x))
except Exception as e:
return Left(InvalidData(e))
data = FilesystemKV[dict](
base_path='path',
extension='.json',
dump=json.dumps,
parse=safe_parse
)
# and then use it as you'd a KV[dict]
Pydantic-validated types
from kv.fs import FilesystemKV, InvalidData
kv = FilesystemKV.validated(tuple[str, int], 'path/to/data') # any JSON/pydantic serializable type should work
# and then use it as you'd a KV[tuple[str, int]]
await kv.read('key-with-invalid-data') # Left(InvalidData(ValidationError(...))
AppendableKV[T]
from kv.fs import FilesystemAppendKV
kv = FilesystemKV.validated(tuple[str, int], 'path/to/data') # stores data as ndjson
await kv.append('key', [('first', 1), ('second', 2)])
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
kv_fs-0.1.18.tar.gz
(4.5 kB
view hashes)
Built Distribution
kv_fs-0.1.18-py3-none-any.whl
(5.0 kB
view hashes)