Crates.io | tinykv |
lib.rs | tinykv |
version | 0.3.0 |
created_at | 2025-07-04 21:49:35.011935+00 |
updated_at | 2025-07-07 21:31:56.417799+00 |
description | A simple, file-backed, human-readable key-value store with TTL support |
homepage | https://github.com/hsnyildiz/tinykv |
repository | https://github.com/hsnyildiz/tinykv |
max_upload_size | |
id | 1738536 |
size | 42,148 |
A minimal file-backed key-value store for Rust with no_std support.
I was working on Tazı (named after the Turkish sighthound), a JS/TS test runner and Jest alternative, when I needed simple persistent storage for test configurations and app settings.
I tried existing solutions:
So I built tinykv - the simple KV store I wish existed. Turns out other Rust developers had the same problem.
serde
for maximum compatibilitynanoserde
for smaller binaries and faster compilation# Default (std + serde)
tinykv = "0.3"
# Embedded systems (no_std + nanoserde)
tinykv = { version = "0.3", default-features = false, features = ["nanoserde"] }
# Ultra-minimal (pure no_std)
tinykv = { version = "0.3", default-features = false }
use tinykv::TinyKV;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut kv = TinyKV::open("settings.json")?
.with_auto_save();
kv.set("theme", "dark")?;
kv.set_with_ttl("session", "abc123", 3600)?; // 1 hour
let theme: String = kv.get("theme")?.unwrap_or("light".to_string());
println!("Using {} theme", theme);
Ok(())
}
The file looks like this:
{
"theme": {
"value": "dark",
"expires_at": null
},
"session": {
"value": "abc123",
"expires_at": 1721234567
}
}
#![no_std]
extern crate alloc;
use tinykv::TinyKV;
fn embedded_main() -> Result<(), tinykv::TinyKVError> {
let mut kv = TinyKV::new(); // In-memory store
kv.set("device_id", "ESP32_001")?;
kv.set("sample_rate", "1000")?;
// Serialize to string for flash storage
let data = kv.to_data()?;
// flash_write(&data)?;
// Load from serialized data
let mut kv2 = TinyKV::from_data(&data)?;
let device_id = kv2.get("device_id");
Ok(())
}
Good for:
Not for:
tinykv works across different environments:
Desktop applications: Full features with file I/O, TTL, backups
Embedded systems: Memory-efficient with nanoserde serialization
WASM projects: Browser-compatible with minimal footprint
IoT devices: Ultra-minimal string-based storage
MIT License - see the full text in the repository.