A tiny Python-like interpreter implemented in Rust.
- Implemented features — language, built-in functions, type methods, math module, optimizer
- Known limitations — what is not yet supported
- Optimizer passes — details of the 15-pass peephole pipeline
# REPL
cargo run
# Run a script
cargo run -- examples/demo.pyOn Windows (PowerShell):
cargo run
cargo run -- examples/demo.pyPyRust is also packaged as a Python distribution via maturin, so it can be installed and run through uv.
# Inside the repo: build and run from the project venv
uv sync
uv run pyrust examples/demo.py
# Or one-shot via uvx (no persistent install)
uvx --from . pyrust examples/demo.py
# Once published to PyPI
uvx pyrust examples/demo.py
uv tool install pyrustNote: uv run pyrust file.py invokes the PyRust binary. There is no way to make uv run file.py use PyRust instead of CPython — uv always dispatches .py scripts to the resolved Python interpreter.
nums = [1, 2, 3]
total = 0
for n in nums:
total += n
print("sum", total) # sum 6
print(nums[::-1]) # [3, 2, 1]cargo test --test parity_compareThis runs all tests/cases/**/test_*.py with CPython and PyRust and compares outputs.
CPython 3.12 is the reference. Some slot semantics (e.g. sorted(reverse=…)'s coercion) differ between 3.11 and 3.12, and pyrust's fixtures lock in 3.12 behaviour. The test harness:
- honours
PYRUST_PYTHONif set, - otherwise uses a
.venv(the repo's.python-versionpins 3.12 souv venvpicks the right interpreter), - falls back to a
python3.12onPATHbefore plainpython3/python, - emits a warning to stderr if the resolved interpreter is older than 3.12.
On Windows — override the Python executable if needed:
$env:PYRUST_PYTHON = "C:\\Python312\\python.exe"
cargo test --test parity_comparecargo build
python tools/benchmark_compare.py --iterations 3 --top 12Optional override for the PyRust binary path:
PYRUST_BIN=target/debug/pyrust python tools/benchmark_compare.pyLive page: https://chanyavrc.github.io/pyrust/
This image is regenerated by GitHub Actions on every push to master.
- CI: GitHub Actions runs on push to
masterand on pull requests.- OS matrix:
ubuntu-latest,windows-latest - Jobs run in parallel:
fmt(Ubuntu):cargo fmt --all --checkunit_and_integration(Ubuntu/Windows):cargo build,cargo testparity(Ubuntu/Windows):cargo build,cargo test --test parity_comparebenchmark(Ubuntu):python tools/benchmark_compare.py --iterations 2 --top 12benchmark-readme(Ubuntu): publishesbenchmark.svgto GitHub Pages
- OS matrix:
- CD: A GitHub Release is published automatically when a tag matching
v*is pushed.- Builds and uploads:
pyrust-linux-x86_64pyrust-windows-x86_64.exe
- Builds and uploads:
git tag v0.1.0
git push origin v0.1.0