Data & Storage — Persisting Without a Server
Most apps don't need a database server on day one. This family gives you crash-safe storage, safe queries, caching and every common data format — all embedded, all zero-dependency.
Reaching for Postgres and an ORM on day one is often overkill — and it's a server to run, secure and back up. The Larz Stack's data family lets you persist safely with nothing but files: a crash-safe embedded database, an injection-proof query builder, caching, migrations, and readers/writers for every format you'll meet.
The data family
From storage up to serialization, each piece is independent.
| Library | What it does |
|---|---|
| larzdb | Crash-safe single-file embedded DB (log-structured, JSON collections, queries) |
| larzsql | Injection-safe SQL builder — every value is a bound parameter |
| larzcache | In-memory LRU/TTL + durable file cache + @memoize |
| larzmigrate | Schema migrations (up/down, checksums) over any DB-API or larzdb |
| larzpack / larzcbor / larzjson / larztoml / larzyaml | Serialize & parse every common format |
Start with larzdb for a whole app in one file; graduate to a real database later using larzsql + larzmigrate without rewriting your data layer.
Safe queries by construction
SQL injection happens when values get concatenated into query strings. larzsql makes that impossible: every value becomes a bound parameter, automatically.
from larzsql import select
sql, params = (select("users")
.where(email=user_input) # value is bound, never inlined
.order_by("-created").limit(10).build())
# sql: SELECT * FROM users WHERE email = ? ORDER BY created DESC LIMIT 10
# params: [user_input] # safely separated from the SQL? placeholder plus a separate params list — there's no way for user input to become executable SQL. Safety is a property of the tool, not something you have to remember to do.Pick storage to match the stage
The data family lets your storage grow with the project instead of forcing a heavy choice up front.
| Stage | Sensible choice |
|---|---|
| Prototype / small app | larzdb — one file, crash-safe, zero setup |
| Need SQL / a real DB | larzsql to build queries + larzmigrate for schema |
| Hot reads / rate limits | larzcache (LRU/TTL, memoize) |
| Config & data exchange | larztoml / larzjson / larzcbor / larzpack |
Every option is zero-dependency, so moving between stages is a code change, not a new piece of infrastructure to run.
🎯 Key takeaways
- The data family: larzdb (embedded DB), larzsql (safe queries), larzcache, larzmigrate, and format libraries.
- larzdb gives crash-safe, single-file storage — a whole app with no database server.
- larzsql is injection-safe by construction: every value is a bound parameter, never inlined SQL.
- Storage can grow with the project — prototype on larzdb, graduate to SQL — all zero-dependency.
Frequently asked
Is a single-file database really safe for real use?
larzdb is log-structured with CRC-checked frames and fsync-on-commit, and it drops torn or corrupt tails on replay — so an interrupted write can't corrupt your data. It's genuinely suitable for small-to-medium apps, background tools, and prototypes. For high-concurrency or very large datasets you'd move to a database server, and larzsql + larzmigrate make that transition smooth.
Why so many format libraries?
Different jobs need different formats: larztoml for config, larzjson for forgiving JSON plus JSON Pointer/Patch, larzcbor and larzpack for compact binary serialization. Each is a separate library so you install only the one you need. They exist because the standard library's own support is partial (e.g. tomllib only reads, and only on new Pythons) — the stack fills the gaps, everywhere, both directions.
Related lessons
Money & Payments — Handling Money Correctly
Money is where sloppy code costs real cash. This family of the stack does money the right …
Building with the Larz StackSecurity & Identity — Crypto You Can Trust
Security code is where 'roll your own' is scariest — so this family sticks to standard, RF…
Building with the Larz StackWeb, AI & Dev Tooling — the Everyday Kit
The libraries you reach for constantly — talking to the web, building AI agents, making CL…