Configs2026年5月30日·1 分钟阅读

RustPython — Python Interpreter Written in Rust

A full Python 3 interpreter implemented in Rust, targeting WebAssembly, embedding, and educational use cases.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
RustPython Overview
直接安装命令
npx -y tokrepo@latest install cf3a1fe0-5c01-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

Introduction

RustPython is a Python 3 interpreter written entirely in Rust. It aims for full CPython compatibility while offering memory safety, easy embedding into Rust applications, and the ability to compile to WebAssembly for browser and edge environments.

What RustPython Does

  • Interprets Python 3 code with a bytecode compiler and virtual machine written in Rust
  • Compiles to WebAssembly so Python can run in browsers without server-side processing
  • Embeds into Rust applications as a scripting engine via a clean Rust API
  • Implements the Python standard library progressively, covering core modules like os, json, and re
  • Passes a growing portion of the CPython test suite to ensure compatibility

Architecture Overview

RustPython uses a multi-phase pipeline: a parser converts Python source into an AST, a compiler transforms the AST into bytecode, and a stack-based virtual machine executes it. The VM manages Python objects through Rust's ownership model, avoiding a global interpreter lock. Each Python object is a Rust struct implementing a PyValue trait, and the garbage collector leverages Rust's reference counting with cycle detection.

Self-Hosting & Configuration

  • Build from source with cargo build --release or install via cargo install
  • Use --target wasm32-wasi for WebAssembly builds
  • Embed by adding rustpython-vm as a Cargo dependency in your Rust project
  • Configure via standard Python mechanisms (PYTHONPATH, site-packages)
  • No external runtime dependencies; single static binary output

Key Features

  • Memory-safe Python execution without a GIL, enabling true parallelism potential
  • WebAssembly compilation for running Python in browsers and serverless environments
  • Clean embedding API for adding Python scripting to Rust applications
  • No C dependencies in the core interpreter, simplifying cross-compilation
  • Active development tracking CPython 3.12+ compatibility

Comparison with Similar Tools

  • CPython — the reference implementation with full ecosystem support; RustPython trades completeness for safety and portability
  • PyPy — JIT-compiled Python for speed; RustPython focuses on embedding and WASM rather than raw performance
  • Pyodide — CPython compiled to WASM via Emscripten; RustPython is a native Rust rewrite rather than a port
  • MicroPython — targets microcontrollers with a minimal subset; RustPython aims for full Python 3 compatibility
  • GraalPython — runs on GraalVM/JVM; RustPython produces standalone native or WASM binaries

FAQ

Q: Can RustPython run my existing Python projects? A: It depends on the project's dependencies. Pure Python code generally works, but C extension modules (numpy, pandas) are not supported.

Q: Is RustPython faster than CPython? A: Not currently for most workloads. The focus is on correctness and portability rather than raw speed.

Q: Can I use pip with RustPython? A: Basic pip support exists, but packages with C extensions will not install. Pure Python packages work.

Q: What Python version does it target? A: RustPython targets Python 3.12+ syntax and semantics, with ongoing work to close compatibility gaps.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产