CLVM Tools Rust
clvm-tools-rs provides a Rust implementation of tools for working with the Chialisp language, including a compiler and REPL, with Python and WebAssembly (WASM) bindings. It is a port of the original clvm_tools to Rust, aiming for improved performance and better alignment with the underlying clvm_rs Rust implementation. The library is actively developed, with its core Rust components seeing frequent updates.
Warnings
- gotcha The `pip install clvm-tools-rs` command installs Python bindings that provide a subset of the command-line tools available when installing via `cargo install clvm_tools_rs`. Specifically, `pip` provides `brun`, `run`, `opc`, and `opd` functionality through Python imports, but other Rust-specific CLI tools might not be exposed this way.
- gotcha There are several related packages: `clvm-tools` (older Python implementation), `clvm-tools-rs` (Rust port with Python bindings), and `clvm_rs` (the underlying Rust CLVM implementation). Ensure you are importing from `clvm_tools_rs` for the Rust-backed Python bindings, as `clvm-tools` is a distinct, older package and `clvm_rs` is the Rust crate name, not the Python package import path.
- gotcha Users on M1 Macs attempting to build `clvm-tools-rs` from source might encounter build issues. The underlying Rust project sometimes requires specific build flags for M1 architecture.
Install
-
pip install clvm-tools-rs
Imports
- compile_clvm
from clvm_tools_rs import compile_clvm
Quickstart
import os
from pathlib import Path
from clvm_tools_rs import compile_clvm
# Create a dummy Chialisp file
chialisp_code = """ (mod (A B)
(+ A B)
) """
# Ensure a temporary directory exists for the output
output_dir = Path("temp_chialisp_output")
output_dir.mkdir(exist_ok=True)
chialisp_file_path = output_dir / "my_program.clsp"
compiled_file_path = output_dir / "my_program.clvm.hex"
with open(chialisp_file_path, "w") as f:
f.write(chialisp_code)
# Compile the Chialisp code
# The compile_clvm function expects strings for paths
compile_result = compile_clvm(str(chialisp_file_path), str(compiled_file_path), [], False)
print(f"Compiled successfully: {compile_result['success']}")
if compile_result['success']:
print(f"Output CLVM hex written to: {compiled_file_path}")
with open(compiled_file_path, "r") as f:
print(f"Compiled CLVM (hex): {f.read().strip()}")
else:
print(f"Compilation error: {compile_result['error']}")
# Clean up temporary files (optional)
# os.remove(chialisp_file_path)
# os.remove(compiled_file_path)
# os.rmdir(output_dir)