Tutorials
Seven guided lessons that start with reading a Lema contract in Pythonic and Lean syntax on any computer, then walk through creating a project, proving contracts with an AI coding agent, reusing theorems, running programs on the Lema VM, and working alongside an agent in store workspaces.
These seven lessons teach Lema step by step. You do not need any background in functional programming, dependent type theory, or theorem proving to follow them. If you have written Python or TypeScript, or if you build software by pairing with an AI coding agent such as Claude Code or Codex, you already have everything you need to start.
Why Lema feels different when you build with AI coding agents
In a traditional file-based repository, asking an AI coding agent to implement a feature or refactor a module leaves you with hundreds of lines of changed source code and a handful of sample unit tests. You either read the entire line diff yourself to look for edge-case bugs, or you hope the agent’s unit tests thought of every corner case.
Lema turns that workflow right-side up:
- You own the short, readable
.lemacontract. You state the rules your code must obey in clean Pythonic syntax (def,contract,law,requires,ensures,forall,select), which fits on a single screen. - Your coding agent writes the implementation and the Lean proof. You can compile, test, and run your implementation on the Lema VM immediately while its contract selection is still
open. When your agent supplies a theorem proving the contract, the pinned Lean 4.34.1 kernel checks that proof across every possible input from scratch, and the store verifies that the theorem binds the exact implementation in your project.
How the seven lessons fit together
- Read your first contract and proof requires zero installation and works on any operating system (macOS, Windows, or Linux). In ten minutes, you will read real contracts in both Pythonic
.lemasyntax and Lean syntax, see howselecttracks an obligation fromopentochecked, and learn how general theorems let you swap implementations without re-proving callers. - Set up a machine for Lema walks through installing the prebuilt
lemaand matchinglema-vm-runneron Linux x86_64 or Apple Silicon macOS, preparing the pinned Lean 4.34.1 checker and library pack withlema setup, checking the sandboxed runtime, and choosing the configuration later commands use. - Create and explore your first project uses
lema new helloto scaffold a project (lema.jsonwith schemalema.project/v1,.lema/store, themainreference, and thedevactor), adds.lemaand.leanmodules withlema add, compares human-readable terminal summaries with--jsonoutput, and renders stored objects back into Pythonic.lemasyntax withlema view. - Select a contract and prove it walks through Lema’s interface-first, proof-optional workflow. You will define a contract (
PreservesZeroondouble, and a multi-lawLawfulEscrowStoragecontract), select it withselect, runlema testandlema runwhile the selection is stillopen, watch your coding agent supply a proof that passesStore::check_witness, and record the result in a semantic revision withlema commit. - Reuse a proof across implementations shows how proving a general theorem once (
twice_id) lets you apply it to multiple implementations (keepandaddZero). You will inspect the five content-addressed objects inside a declaration (declaration,statement,template,proof, andsatisfaction) to see why hashes stay stable when proofs change, and uselema diffto inspect semantic changes. - Run and release a program on the Lema VM takes accepted store objects to a running program. You will run pure
ByteArraytests withlema test, run interactiveProgapplications on the Lema VM withlema run(including automatic command-family inference intolema.exec/v2and<store>/vm-code-cachereuse), watch source edits withlema dev, and cut a verified release withlema releaseandlema run --release. - Work alongside an agent in store workspaces gives a coding agent a store workspace and a directory of its own. You will register it as a store actor, author
.lemaand.leanmodules on both sides at once, see that each workspace reads only its own work, watch the server’s activity as the agent works, and land its commits onmainwith a three-way merge, recovering from a policy refusal and a conflict on the way.
Where to start
For a running local web application, start with Get started with Lema, which takes you through the HTTPS echo starter and its edit, check and run loop. To learn the proof workflow first, begin with Lesson 1: Read your first contract and proof. The proved HTTPS stack explains how the libraries cover cryptography, TLS 1.3, HTTP/1.1 and S3 over Lema’s six byte-level capability tags.
Lema v0.3.2 · Updated 29 October 2026 · Version and compatibility