https://github.com/distributive-network/pythonmonkey-rust-wasm-example
🐍 Executing Rust from Python using WASM 🦀
https://github.com/distributive-network/pythonmonkey-rust-wasm-example
example python rust
Last synced: 3 months ago
JSON representation
🐍 Executing Rust from Python using WASM 🦀
- Host: GitHub
- URL: https://github.com/distributive-network/pythonmonkey-rust-wasm-example
- Owner: Distributive-Network
- Created: 2023-07-21T13:21:09.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-07-21T13:44:57.000Z (almost 2 years ago)
- Last Synced: 2025-01-10T19:47:53.652Z (4 months ago)
- Topics: example, python, rust
- Language: Shell
- Homepage:
- Size: 1.95 KB
- Stars: 1
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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](https://pythonmonkey.io/), a Python library for executing
JavaScript and WebAssembly from Python. [Check it out on GitHub](https://github.com/Distributive-Network/PythonMonkey)!## 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:
```sh
$ ./build.sh
```Run:
```sh
$ 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.