Skip to content

Export and import a project or library bundle

Transfer a self-contained project checkpoint (.lema.bundle) across machines with lema export and lema import, or package reusable library exports into a lema.bundle/v1 record.

Because a Lema project’s semantic history, kernel receipts, and contract selections live inside .lema/store, copying .lema and .lean source files alone does not transfer your verified codebase. Instead, Lema provides two content-addressed packaging tools:

  1. Project checkpoints (lema export and lema import, lema.checkpoint/v1): Exports a complete, self-contained closure of a project reference (main), its revisions, snapshots, authoring bundles, contract selections, and canonical objects into a single .lema.bundle file, and replays every object through the pinned Lean 4.34.1 kernel when imported into a fresh store.
  2. Library bundles (lema call bundle.create, lema.bundle/v1): Groups a set of accepted library declarations under clean export names inside a store so downstream modules can receive all of them at once without wiring individual Received.* object IDs by hand.

Before you start

  • A Lema project with accepted objects and at least one committed revision (Work with a Lema project).
  • On the machine where you run lema import, the pinned Lean 4.34.1 checker installed (lema toolchain install), because importing a checkpoint replays every object through the receiving machine’s Lean kernel rather than trusting external receipts.

Part 1: Export and import a project (lema export and lema import)

1. Export your project reference to a .lema.bundle file

From inside your project directory, run lema export:

Shell
lema export counter.lema.bundle --ref main
Output
exported counter.lema.bundle (sha256: 6b4e9102c8a3…, 198 objects, 3 revisions)

lema export FILE [--ref NAME..] wraps the store’s checkpoint exporter (crates/lema-store/src/records/checkpoint.rs, lema.checkpoint/v1). It computes the full transitive closure of the selected project references (including their lema.revision/v1 history, lema.snapshot/v2 records, lema.authoring/v2 source bundles, lema.contract/v1 contract selections, and all canonical lema.core/v4 objects) and writes them into a deterministic archive along with its SHA-256 digest.

2. Import the bundle into a new project directory

On another machine (or in a new directory on the same host), run lema import:

Shell
lema import counter.lema.bundle restored-counter
cd restored-counter
lema status
Output
imported counter.lema.bundle into restored-counter (replayed 198 objects, 0 axiom violations)
server: running (pid 61029, socket /home/you/restored-counter/.lema/lema.sock)
store:  /home/you/restored-counter/.lema/store (accepted: 198, aliases: 45)
ref:    main (revision: #a19f402e8d11, generation: 3, policy_version: 1)
contracts: 2 selected (1 checked, 1 open)

Look at what lema import verifies before accepting the project:

  1. Archive integrity and topological closure: Checks the bundle schema (lema.checkpoint/v1), verifies every object’s SHA-256 hash against its canonical contents, and confirms that no dependencies are missing.
  2. Source-free Lean 4.34.1 kernel replay: Replays every declaration, record, inductive family, and contract selection check theorem in the bundle through the receiving host’s pinned Lean 4.34.1 kernel inside the bubblewrap sandbox, and verifies that every declaration’s transitive axiom footprint obeys the receiving store’s axiom policy. A store never trusts kernel receipts from another machine.
  3. Workspace reconstruction: Reconstructs lema.json, restores the authored .lema and .lean files under src/ from the verified lema.authoring/v2 records, sets up the main reference at its exact revision and generation, and starts the background server.

Low-level checkpoint export/import for non-project stores

When working directly against a store socket (for example, when staging a minimal deployment store on a build host as described in Release an application), you can also invoke lema checkpoint export and lema checkpoint import by root ID and expected SHA-256:

Shell
lema checkpoint export --root $EXEC_RECORD_ID --out ledger.lemabundle --socket $BUILD_SOCK
lema checkpoint import ledger.lemabundle --sha256 $BUNDLE_SHA256 --socket $FRESH_SOCK

Part 2: Group reusable exports into a library bundle (lema.bundle/v1)

When you build a foundational library in .lema/store that exports ten or twenty related types, operations, and theorems (such as Std.Map or Std.ChaCha20Poly1305), a library bundle (lema.bundle/v1, crates/lema-store/src/bundle.rs) lets you package those accepted object IDs under clean export names in a single immutable store record.

1. Create a library bundle from aliases (bundle.create)

Suppose your store has aliases core.Prog, core.Prog.call, core.Prog.ret, and core.Safe. Create core-bundle.json and call bundle.create:

core-bundle.json
{
  "from_aliases": [
    {"alias": "core.Prog", "name": "Prog"},
    {"alias": "core.Prog.call", "name": "Prog.call"},
    {"alias": "core.Prog.ret", "name": "Prog.ret"},
    {"alias": "core.Safe", "name": "Safe"}
  ],
  "doc": "Core v2 programs and safety."
}
Shell
lema call bundle.create --params-file core-bundle.json

The server resolves each alias to its current accepted object ID (and role) at the moment bundle.create runs, writes an immutable lema.bundle/v1 record, and returns {id, created, exports}. Moving those aliases later will never alter the created bundle.

You can also create a bundle directly from {name, id, role?} entries using "exports": [...], mark internal lemmas with "helpers": [...] (hidden from default bundle.list summaries while still bound when received), and document upstream bundle IDs with "depends": [...].

2. Inspect and receive a library bundle (bundle.list, bundle.get, --receive)

List all library bundles in your store or inspect a single bundle by ID:

Shell
lema call bundle.list --params '{"names": true}'
lema call bundle.get --params '{"id": "<bundle_id>"}'

To use a library bundle when publishing a single file with lema publish, pass --receive BUNDLE_ID=PREFIX (or pass a receive array in JSON-RPC with optional as namespace prefixes and rename maps):

Shell
lema publish src/Client.lean --receive $CORE_BUNDLE_ID=Core

Every export N in the bundle becomes available in src/Client.lean as Received.Core.N, producing the exact same content-addressed declarations as if you had listed every Received.* binding by hand.

Common refusals

Refusal message containsCause and fix
vm-only: Lean calls refusedlema import was run against a VM-only runtime configuration that omits distribution. Point --runtime at a full checking configuration with Lean 4.34.1 installed.
depends on Classical.choice, outside the store's axiom policyThe receiving store was initialized with a narrower axiom policy than the exporting store (Create a store with a narrower axiom policy).
Received.Prog is bound twice: by ...Two received library bundles (or a bundle and an explicit binding) export the same target name. Disambiguate them with an as prefix or rename map.
dotted identifier Lean parsesA library bundle export name contains characters like ? or ! (for example, find?). Export it under a plain identifier such as find.

Lema v0.3.2 · Updated 29 October 2026 · Version and compatibility