Back to browse
GitHub Repository

SNKV — a lightweight key-value store focused on simplicity, security and performance file based database , written using b-tree directly. Now supports vector HNSW , Join the discussion: https://discord.gg/EUb4Y5qE

76 starsC

SNKV – SQLite's B-tree as a key-value store (C/C++ and Python bindings)

by swaminarayan·Feb 24, 2026·36 points·31 comments

AI Analysis

●●●BangerWizardryBig Brain

SQLite B-tree without SQL: 57–68% faster KV ops, single-header drop-in.

Strengths
  • Clever architectural insight: SQLite's bottom three layers are production-proven; cutting the top eliminates overhead without reinventing storage
  • Span-based parsing (4-byte views into buffer, O(1) header lookup) shows exceptional low-level craft
  • Drop-in C/C++ header and PyPI Python package; zero external deps, ACID guarantees inherited from SQLite
Weaknesses
  • No distributed replication or advanced query features (inherent to KV-only design)
  • Narrow use case: only shines for pure key-value workloads; SQL users lose flexibility
Target Audience

Systems engineers, database developers, embedded systems programmers needing crash-safe KV storage

Similar To

RocksDB · LMDB · LevelDB

Post Description

SQLite has six layers: SQL parser → query planner → VDBE → B-tree → pager → OS. (https://sqlite.org/arch.html) For key-value workloads you only need the bottom three.

SNKV cuts the top three layers and talks directly to SQLite's B-tree engine. No SQL strings. No query planner. No VM. Just put/get/delete on the same storage core that powers SQLite.

Python:

pip install snkv

from snkv import KVStore

with KVStore("mydb.db") as db: db["hello"] = "world" print(db["hello"]) # b"world"

C/C++ (single-header, drop-in):

#define SNKV_IMPLEMENTATION #include "snkv.h"

KVStore *db; kvstore_open("mydb.db", &db, KVSTORE_JOURNAL_WAL); kvstore_put(db, "key", 3, "value", 5);

Benchmarks vs SQLite WITHOUT ROWID (1M records, identical settings):

Sequential writes +57% Random reads +68% Sequential scan +90% Random updates +72% Random deletes +104% Exists checks +75% Mixed workload +84% Bulk insert +10%

Honest tradeoffs: - LMDB beats it on raw reads (memory-mapped) - RocksDB beats it on write-heavy workloads (LSM-tree) - sqlite3 CLI won't open the database (schema layer is bypassed by design)

What you get: ACID, WAL concurrency, column families, crash safety — with less overhead for read-heavy KV workloads.

Similar Projects

AI/ML●●Solid

AgentKV – SQLite for AI agent memory (MMAP vector+graph DB)

Single-file mmap storage plus an HNSW vector index and explicit graph edges is an elegant, practical combo — think "SQLite for agent memory" with CRC-32 crash recovery and zero-server convenience. The C++20 core + nanobind gives zero-copy NumPy views and GIL-free searches, and the claimed FAISS-like throughput makes this genuinely interesting for local setups; main caveat is build/toolchain friction and how rich the surrounding ecosystem becomes.

WizardryNiche Gem
shiwang_khera
103mo ago