Metadata-Version: 2.1
Name: python-kv
Version: 0.2.3
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: fs
Requires-Dist: fs-tools; extra == "fs"
Provides-Extra: sql
Requires-Dist: sqlmodel; extra == "sql"
Requires-Dist: sqltypes; extra == "sql"
Provides-Extra: redis
Requires-Dist: redis; extra == "redis"
Provides-Extra: azure
Requires-Dist: azure-storage-blob; extra == "azure"
Requires-Dist: aiohttp; extra == "azure"
Provides-Extra: server
Requires-Dist: fastapi; extra == "server"
Requires-Dist: uvicorn; extra == "server"
Provides-Extra: client
Requires-Dist: httpx; extra == "client"
Provides-Extra: cli
Requires-Dist: typer; extra == "cli"
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"

# 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
```

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