Metadata-Version: 2.1
Name: python-kv
Version: 0.2.5
Summary: Async, exception-free key-value store ABC. Implementations over SQLAlchemy, the filesystem, Redis, Azure Blob, and more.
Author-email: Marcel Claramunt <marcel@moveread.com>
Project-URL: repo, https://github.com/marciclabas/kv.git
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: haskellian
Requires-Dist: pydantic
Requires-Dist: lazy-loader
Provides-Extra: all
Requires-Dist: fs-tools ; extra == 'all'
Requires-Dist: sqlmodel ; extra == 'all'
Requires-Dist: redis ; extra == 'all'
Requires-Dist: azure-storage-blob ; extra == 'all'
Requires-Dist: aiohttp ; extra == 'all'
Requires-Dist: fastapi ; extra == 'all'
Requires-Dist: uvicorn ; extra == 'all'
Requires-Dist: httpx ; extra == 'all'
Requires-Dist: typer ; extra == 'all'
Provides-Extra: blob
Requires-Dist: azure-storage-blob ; extra == 'blob'
Requires-Dist: aiohttp ; extra == 'blob'
Provides-Extra: cli
Requires-Dist: typer ; extra == 'cli'
Provides-Extra: client
Requires-Dist: httpx ; extra == 'client'
Provides-Extra: cosmos
Requires-Dist: azure-cosmos ; extra == 'cosmos'
Requires-Dist: aiohttp ; extra == 'cosmos'
Provides-Extra: fs
Requires-Dist: fs-tools ; extra == 'fs'
Provides-Extra: redis
Requires-Dist: redis ; extra == 'redis'
Provides-Extra: server
Requires-Dist: fastapi ; extra == 'server'
Requires-Dist: uvicorn ; extra == 'server'
Provides-Extra: sql
Requires-Dist: sqlmodel ; extra == 'sql'
Requires-Dist: sqltypes ; extra == 'sql'

# KV

> Async, exception-free key-value store ABC. Implementations over SQLAlchemy, the filesystem, Redis, Azure Blob, and more.

```bash
pip install python-kv
```

## Usage

```python
from kv import KV

kv = KV.of('sql+sqlite:///path/to/db.sqlite') # easiest way to switch backends: connection strings

await kv.insert('key', 'value') # Left[DBError] | Right[None]
await kv.read('key') # Left[ReadError] | Right['value']
await kv.delete('key') # Left[DBError] | Right[None]
[k async for k in kv.keys()] # list[Left[ReadError] | Right[T]]
[it async for it in kv.items()] # list[Left[ReadError] | Right[tuple[str, T]]]
await kv.clear() # Left[DBError] | Right[None]
# and a few more
```

## Serialization & Validation
  
```python
from dataclasses import dataclass

@dataclass
class MySerializableType:
  a: int
  b: str

kv = KV.of('sql+sqlite://...', MySerializableType)
await kv.insert('key', MySerializableType(1, '2')) # Left[InvalidData] | Right[None]
# etc.
```

## CLI
  
```bash
kv serve 'file://data' --token "shhhhh" --port 8080 --type dict
kv serve 'sql+postgresql+psycop2g://...' --port 8081 --type str
```

```bash
kv copy -i 'file://data' -o 'sql+sqlite:///path/to/db.sqlite' -v
kv copy -i 'https://my.com/data' -o 'sql+sqlite:///path/to/db.sqlite'
```


```bash
kv test CONN_STR # runs some basic tests
```
