#python #wasm-interpreter #python-3 #cpython #rustpython #compiler

rustpython_wasm

A Python-3 (CPython >= 3.5.0) Interpreter written in Rust, compiled to WASM

2 unstable releases

0.4.0 Aug 7, 2024
0.3.0 Sep 6, 2023

#980 in WebAssembly

Download history 2/week @ 2024-07-27 124/week @ 2024-08-03 5/week @ 2024-08-10 15/week @ 2024-09-14 11/week @ 2024-09-21 26/week @ 2024-09-28 1/week @ 2024-10-05

71 downloads per month

MIT and LGPL-3.0-only

5.5MB
119K SLoC

Rust 72K SLoC // 0.0% comments Python 48K SLoC // 0.3% comments PowerShell 26 SLoC // 0.5% comments Batch 10 SLoC

RustPython

A Python-3 (CPython >= 3.8.0) Interpreter written in Rust.

Build Status License: MIT

WARNING: this project is still in a pre-alpha state!

Using this in a production project is inadvisable. Please only do so if you understand the risks.

Usage

Check out our online demo running on WebAssembly.

Goals

  • Full Python-3 environment entirely in Rust (not CPython bindings)
  • A clean implementation without compatibility hacks

Quick Documentation

pyEval(code, options?);

code: string: The Python code to run

options:

  • vars?: { [key: string]: any }: Variables passed to the VM that can be accessed in Python with the variable js_vars. Functions do work, and receive the Python kwargs as the this argument.
  • stdout?: "console" | ((out: string) => void) | null: A function to replace the native print function, and it will be console.log when giving undefined or "console", and it will be a dumb function when giving null.

License

This project is licensed under the MIT license.

Dependencies

~36–71MB
~1M SLoC