Skip to main content

Key-Value interface over SQLite. Supports any datatype, including JSON and BLOB

Project description

Key-Value: SQLite3

Implementation of the KV[T]async Key-Value ABC, over python's sqlite3

pip install kv-sqlite-sync

Usage

Custom serialization

from kv.sqlite import SQLiteKV, InvalidData
from haskellian import Either, Left, Right
import json

def safe_parse(x: str) -> Either[InvalidData, dict]:
  try:
    return Right(json.loads(x))
  except Exception as e:
    return Left(InvalidData(e))
  
kv = SQLiteKV[dict].at(
  db_path='mydb.sqlite', table='my-jsons',
  dtype='JSON', parse=json.loads, dump=json.dumps
)

await kv.insert('key1', {'a': 1, 'b': 2})

Pydantic-validated types

from kv.sqlite import SQLiteKV

kv = SQLiteKV.validated(
  tuple[str, int],
  db_path='mydb.sqlite', table='my-tuples',
)

await kv.insert('key1', ('a', 1))

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_sqlite_sync-0.1.13.tar.gz (3.7 kB view hashes)

Uploaded Source

Built Distribution

kv_sqlite_sync-0.1.13-py3-none-any.whl (4.3 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