Chialisp Python Tools
A pure Python implementation of Chialisp tools, including the CLVM (Chia's Lisp Virtual Machine), compiler, and standard library. It provides utilities for assembling and disassembling Chialisp programs, and interfaces with `clvm_tools_rs` for performance. Currently at version 0.4.3, its release cadence is tied to updates in the broader Chia ecosystem and CLVM specification.
Common errors
-
ERROR: Could not build wheels for clvm-tools-rs, which is required to install pyproject.toml-based projects
cause The underlying `clvm_tools_rs` Rust package could not be compiled because a Rust toolchain (compiler, cargo) is missing or misconfigured on your system.fixInstall Rust and Cargo using `curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh` (Linux/macOS) or download from `rustup.rs`. Ensure Rust is in your system's PATH. -
ModuleNotFoundError: No module named 'chialisp.clvm_tools.binutils'
cause The `chialisp` package is not installed in your current environment, or the import path is incorrect (e.g., a typo in `binutils`).fixEnsure `chialisp` is installed with `pip install chialisp`. Verify that your Python environment is active and the import statement matches official documentation. -
Error: Bad encoding for atom 2 2
cause Invalid Chialisp syntax, incorrect data types, or a malformed expression provided to `assemble` or `compile_clvm`.fixReview the Chialisp program for correct syntax, valid opcodes, and appropriate atom encoding. Consult the official Chialisp documentation for syntax rules and examples.
Warnings
- gotcha Installation may fail if pre-compiled wheels for the `clvm_tools_rs` dependency are not available for your platform and a Rust toolchain is not installed on your system.
- gotcha The interpretation and compilation of Chialisp programs can change between versions due to updates in the underlying CLVM specification or compiler logic.
- gotcha While `chialisp` depends on `clvm_tools_rs`, its core functionalities are exposed through the `chialisp.clvm_tools` namespace. Direct imports from `clvm_tools_rs` are generally not intended for external use and may lead to unexpected behavior or API instability.
Install
-
pip install chialisp
Imports
- assemble
from chialisp.clvm_tools.binutils import assemble
- disassembler
from chialisp.clvm_tools.binutils import disassembler
- compile_clvm
from chialisp.clvm_tools.clvmc import compile_clvm
Quickstart
from chialisp.clvm_tools.binutils import assemble, disassembler
# Chialisp source code
chialisp_source = "(a (q 2 2) (q 1 3))"
# 1. Assemble Chialisp source into a CLVM program (bytes)
print(f"Original Chialisp source: {chialisp_source}")
assembled_program = assemble(chialisp_source)
print(f"Assembled CLVM program (bytes): {assembled_program.hex()}")
# 2. Disassemble a CLVM program back into Chialisp source (approximate)
disassembled_source = disassembler(assembled_program)
print(f"Disassembled Chialisp source: {disassembled_source}")
# Example with a slightly more complex structure
complex_source = "(a (q . 1) (q (a (q 2 2) (q 1 3)) (c (q 5) (q 1))))"
assembled_complex = assemble(complex_source)
print(f"\nComplex Chialisp source: {complex_source}")
print(f"Assembled complex program (bytes): {assembled_complex.hex()}")
print(f"Disassembled complex program: {disassembler(assembled_complex)}")