lmcode-python skill
Use lmcode-python to embed the DSLB v6 bytecode verifier, 206-signature standard catalog, and opt-in REST controller into Python 3.9+ applications.
Purpose
Execute schema-bound lmcode DSLB v6 bytecode in pure Python with zero third-party runtime dependencies, opt-in REST dispatch, and LMCODE_RETURN framing.
When to use it
Use lmcode-python when authoring a Python CLI, service, or test harness that exposes Python objects or REST endpoints to compiled lmcode chunks.
Install
Install with python -m pip install lmcode-python (or pip install -e . from a checkout) on Python 3.9 or newer.
Commands
python3 -m unittest discover -s tests
python3 scripts/check-verifier-mutations.py
python3 -m lmcode.conformance conformance/vectors
python3 scripts/run-rest-suite.py
python3 -m lmcode.rest app.dslb host.schema.json
Inputs and outputs
- Input: bytes DSLB v6 bytecode, bytes dsl.schema: 2 JSON, and optional LMCODE_INVOCATION_FILE manifest.
- Output: mutated Python objects in Context, HTTP/1.1 responses on stdout via RestController, or a terminal LMCODE_RETURN frame.
- Strings: callbacks receive UTF-8 str by default; pass raw_strings=True to receive latin1 one-codepoint-per-byte raw strings.
Safety rules
- Set raw_strings=True on Registry.function or Registry.method when callbacks handle arbitrary binary bytes or invalid UTF-8.
- Wrap dry-mode preview callbacks with lmcode.dry(fn) so mutating callbacks remain skipped during dry runs.
- Keep stdout clean while RestController is serving HTTP/1.1 over sys.stdout.buffer; direct diagnostics to sys.stderr.
Worked examples
from pathlib import Path
from lmcode import Context, Registry, dry, load
registry = Registry()
registry.function(
"double_it", ["int"], "int",
lambda ctx, args: (args[0] * 2) & 0xFFFFFFFFFFFFFFFF,
dry_callback=dry(lambda ctx, args: 0),
)
program = load(Path("chunk.dslb").read_bytes(), Path("host.schema.json").read_bytes(), registry)
program.run(Context(), registry)
Errors and exit codes
| Code | Phase | Exit | Condition |
|---|---|---|---|
| LOAD_BAD_BYTECODE | load | 3 | Malformed DSLB v6 header, bad magic or version, truncated section, invalid opcode, or stack depth violation |
| LOAD_BAD_SCHEMA | load | 3 | Host schema JSON fails dsl.schema 2 validation or declares an invalid result contract |
| LOAD_SCHEMA_MISMATCH | load | 3 | 32-byte SHA-256 schema hash in DSLB v6 header does not match exact host schema bytes |
| LOAD_UNBOUND | load | 3 | Bytecode imports a context, function, or method signature not registered in the host Registry |
| RUN_ERROR | run | 3 | VM division or remainder by zero, or loop-free operand stack underflow |
| RUN_HOST | run | 3 | Host callback failure, invalid encoding, expired collection handle, or REST route validation failure |
| APP_FAIL | app | 4 | Post-run application domain validation failure or output stream write failure |
How to verify
bash scripts/sync-std.sh --verify
python3 scripts/sync-rest.py --verify
python3 -m unittest discover -s tests
python3 scripts/run-rest-suite.py