Skip to content

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 .lema contract. 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

  1. 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 .lema syntax and Lean syntax, see how select tracks an obligation from open to checked, and learn how general theorems let you swap implementations without re-proving callers.
  2. Set up a machine for Lema walks through installing the prebuilt lema and matching lema-vm-runner on Linux x86_64 or Apple Silicon macOS, preparing the pinned Lean 4.34.1 checker and library pack with lema setup, checking the sandboxed runtime, and choosing the configuration later commands use.
  3. Create and explore your first project uses lema new hello to scaffold a project (lema.json with schema lema.project/v1, .lema/store, the main reference, and the dev actor), adds .lema and .lean modules with lema add, compares human-readable terminal summaries with --json output, and renders stored objects back into Pythonic .lema syntax with lema view.
  4. Select a contract and prove it walks through Lema’s interface-first, proof-optional workflow. You will define a contract (PreservesZero on double, and a multi-law LawfulEscrowStorage contract), select it with select, run lema test and lema run while the selection is still open, watch your coding agent supply a proof that passes Store::check_witness, and record the result in a semantic revision with lema commit.
  5. Reuse a proof across implementations shows how proving a general theorem once (twice_id) lets you apply it to multiple implementations (keep and addZero). You will inspect the five content-addressed objects inside a declaration (declaration, statement, template, proof, and satisfaction) to see why hashes stay stable when proofs change, and use lema diff to inspect semantic changes.
  6. Run and release a program on the Lema VM takes accepted store objects to a running program. You will run pure ByteArray tests with lema test, run interactive Prog applications on the Lema VM with lema run (including automatic command-family inference into lema.exec/v2 and <store>/vm-code-cache reuse), watch source edits with lema dev, and cut a verified release with lema release and lema run --release.
  7. 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 .lema and .lean modules 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 on main with 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