Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

kachedb

High-Performance Python Client for KacheDB — The Zero-Copy Redis-Compatible & LLM KV-Cache Storage Engine

PyPI Version Python Versions CI License


⚡ Installation

pip install kachedb

With PyTorch tensor support:

pip install kachedb[torch]

🚀 Quickstart

Synchronous Client

from kachedb import KacheClient

with KacheClient(host="127.0.0.1", port=6379) as client:
    # Standard Redis-compatible operations
    client.set("user:1", "alice", ex=3600)     # SET with 1-hour TTL
    print(client.get("user:1"))                 # b"alice"

    # Batch operations
    client.set("user:2", "bob")
    result = client.mget("user:1", "user:2")    # [b"alice", b"bob"]

    # Check existence
    print(client.exists("user:1"))              # 1

    # Delete
    client.delete("user:1", "user:2")

Async Client

import asyncio
from kachedb import AsyncKacheClient

async def main():
    async with AsyncKacheClient(host="127.0.0.1", port=6379) as client:
        await client.set("key", "value", ex=60)
        result = await client.get("key")
        print(result)  # b"value"

asyncio.run(main())

Pipeline Batching

Reduce network round-trips by batching multiple commands:

from kachedb import KacheClient

with KacheClient() as client:
    pipe = client.pipeline()
    pipe.set("a", "1")
    pipe.set("b", "2")
    pipe.set("c", "3")
    pipe.get("a")
    pipe.get("b")
    pipe.get("c")

    results = pipe.execute()
    # ["OK", "OK", "OK", b"1", b"2", b"3"]

Async Pipeline

from kachedb import AsyncKacheClient

async def main():
    async with AsyncKacheClient() as client:
        pipe = client.pipeline()
        pipe.set("x", "10")
        pipe.get("x")
        results = await pipe.execute()
        # ["OK", b"10"]

Zero-Copy Tensor Access (LLM KV-Cache)

Read KV-cache tensors directly from KacheDB's shared memory with zero data copying:

from kachedb import read_tensor, read_torch_tensor

# Read as numpy array (zero-copy via /dev/shm)
np_tensor = read_tensor(core_id=0, byte_offset=0)
print(np_tensor.shape, np_tensor.dtype)

# Read as PyTorch tensor (requires: pip install kachedb[torch])
torch_tensor = read_torch_tensor(core_id=0, byte_offset=0)
print(torch_tensor.shape, torch_tensor.dtype)

📋 Supported Commands

All commands follow the KacheDB RESP2/RESP3 wire protocol:

Command Method Description
PING client.ping() Test server liveness
SET client.set(key, value, ex=, px=) Store value with optional TTL
GET client.get(key) Retrieve value
MGET client.mget(*keys) Batch retrieve multiple keys
DEL client.delete(*keys) Delete keys
EXISTS client.exists(*keys) Count existing keys

🏗️ Architecture

┌──────────────────────────────────────────────────────────┐
│                     Your Python App                      │
│             (vLLM / SGLang / FastAPI / etc.)             │
├──────────────────────────────────────────────────────────┤
│                   kachedb Python SDK                     │
│  ┌──────────────┐  ┌──────────────┐  ┌────────────────┐  │
│  │ KacheClient  │  │  AsyncKache  │  │    Pipeline    │  │
│  │  (sync TCP)  │  │    Client    │  │    Batching    │  │
│  └──────┬───────┘  └──────┬───────┘  └───────┬────────┘  │
│         │                 │                  │           │
│  ┌──────┴─────────────────┴──────────────────┴────────┐  │
│  │            RESP2/RESP3 Protocol Engine             │  │
│  │         (64KB buffered encoder + decoder)          │  │
│  └──────────────────────┬─────────────────────────────┘  │
│                         │                                │
│  ┌──────────────────────┴─────────────────────────────┐  │
│  │        ConnectionPool / AsyncConnectionPool        │  │
│  │    (Thread-safe / asyncio.Queue, health checks)    │  │
│  └──────────────────────┬─────────────────────────────┘  │
├─────────────────────────┼────────────────────────────────┤
│                   TCP + /dev/shm                         │
├──────────────────────────────────────────────────────────┤
│                  KacheDB Server (Rust)                   │
│         io_uring / kqueue │ POSIX SHM │ Megaslab         │
└──────────────────────────────────────────────────────────┘

🔧 Connection Pool

The client automatically manages a connection pool:

from kachedb import KacheClient

# Pool with up to 20 connections
client = KacheClient(
    host="127.0.0.1",
    port=6379,
    max_connections=20,
    socket_timeout=5.0,
)

🧪 Development

# Clone
git clone https://github.com/vubon/kachedb-py.git
cd kachedb-py

# Install in dev mode
pip install -e ".[dev]"

# Run unit tests
pytest tests/ -v --ignore=tests/test_integration.py

# Run integration tests (requires running KacheDB server)
pytest tests/test_integration.py -v

# Lint
ruff check src/ tests/
ruff format --check src/ tests/

# Type check
mypy src/kachedb/

🔗 Related Projects

📄 License

Dual-licensed under either of:

at your option.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kachedb-0.1.0a2.tar.gz (24.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kachedb-0.1.0a2-py3-none-any.whl (24.6 kB view details)

Uploaded Python 3

File details

Details for the file kachedb-0.1.0a2.tar.gz.

File metadata

  • Download URL: kachedb-0.1.0a2.tar.gz
  • Upload date:
  • Size: 24.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for kachedb-0.1.0a2.tar.gz
Algorithm Hash digest
SHA256 9ba7ad5647c62408b09d24d368416b7dbc2638551208d34de5747c4cb4f71802
MD5 a33607fc59770e2fb7483fdb7658a43c
BLAKE2b-256 b59569978bac395a5d2aab3aaf57b7f0d6a2cb964e7475aad928191db0f20dcd

See more details on using hashes here.

Provenance

The following attestation bundles were made for kachedb-0.1.0a2.tar.gz:

Publisher: publish.yml on vubon/kachedb-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kachedb-0.1.0a2-py3-none-any.whl.

File metadata

  • Download URL: kachedb-0.1.0a2-py3-none-any.whl
  • Upload date:
  • Size: 24.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for kachedb-0.1.0a2-py3-none-any.whl
Algorithm Hash digest
SHA256 af655139f116d70e8635a017fa897f736e5904ede01ee9322b40b0b59e30d6e1
MD5 97ffe81d158420cdac00409dddd73a61
BLAKE2b-256 a62ef8e8b8ff602f2acc42f4a07443b13cbb83b1964dddc3654c6d6cbc83442e

See more details on using hashes here.

Provenance

The following attestation bundles were made for kachedb-0.1.0a2-py3-none-any.whl:

Publisher: publish.yml on vubon/kachedb-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.0a2 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page