Skip to main content

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


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 details)

Uploaded Source

Built Distribution

kv_fs-0.1.18-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file kv_fs-0.1.18.tar.gz.

File metadata

  • Download URL: kv_fs-0.1.18.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.6

File hashes

Hashes for kv_fs-0.1.18.tar.gz
Algorithm Hash digest
SHA256 80cc6795c7e6969e1ee1e23ba98a0b2c21527fdd7db87be99dec9bb0527d4813
MD5 e428d1ea10c81013c5f5fee3b3b31fd5
BLAKE2b-256 4273336a55738d195f4476ccda356f8a8321d9fa93c66d07eca2c12bac91fec5

See more details on using hashes here.

File details

Details for the file kv_fs-0.1.18-py3-none-any.whl.

File metadata

  • Download URL: kv_fs-0.1.18-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.6

File hashes

Hashes for kv_fs-0.1.18-py3-none-any.whl
Algorithm Hash digest
SHA256 ce27e6c469160dffb8d2fdcfe0ba994fc7e9d0ceb8325498f58a8703bfe65fa2
MD5 37e785a95796cfdc09f152e4c78de885
BLAKE2b-256 e0d9bf4dc843a774cb18ef0c7a2e09b255db542829b99358cc6d9f70185c0406

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