Skip to content

Distributive-Network/pythonmonkey-rust-wasm-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

PythonMonkey Rust WebAssembly Example

This example demonstrates compiling a Rust library to WebAssembly, creating a JavaScript package api for it, and calling it from Python.

This is accomplished using PythonMonkey, a Python library for executing JavaScript and WebAssembly from Python. Check it out on GitHub!

Required Software Installation

Install Rust + Cargo: https://doc.rust-lang.org/cargo/getting-started/installation.html

Install wasm-pack using Cargo: $ cargo install wasm-pack

Install Python with a minimum version of 3.8.

Install PythonMonkey using pip: $ pip install pythonmonkey

Compile and Run

Compile:

$ ./build.sh

Run:

$ python3 main.py

Note: Temporary Shim

Support for Node.js libraries with PythonMonkey is currently a work in progress so the build.sh script is required to convert Node.js specific code to PythonMonkey friendly code. This is performed by replacing readFileSync with Python's open and writing a simple pure JS version of join from the path library.

About

🐍 Executing Rust from Python using WASM πŸ¦€

Topics

Resources

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published