🧱
🧱 Building with the Larz Stack · STK-101 · Session 3 of 8

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.

⏱ 9 min read📅 Updated 2026-07-26📊 Tables, charts & examples

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.

LibraryWhat it does
larzdbCrash-safe single-file embedded DB (log-structured, JSON collections, queries)
larzsqlInjection-safe SQL builder — every value is a bound parameter
larzcacheIn-memory LRU/TTL + durable file cache + @memoize
larzmigrateSchema migrations (up/down, checksums) over any DB-API or larzdb
larzpack / larzcbor / larzjson / larztoml / larzyamlSerialize & 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
🎯
Injection-safe by design, not by discipline. Because larzsql never puts a value into the SQL text — only a ? 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.

StageSensible choice
Prototype / small applarzdb — one file, crash-safe, zero setup
Need SQL / a real DBlarzsql to build queries + larzmigrate for schema
Hot reads / rate limitslarzcache (LRU/TTL, memoize)
Config & data exchangelarztoml / 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.

Session 3 of 8 complete

Next up: Security & Identity — Crypto You Can Trust

Continue to Session 4 →

Related lessons

More in this course

Course home → · Browse all courses →