Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wiwichips/pythonmonkey-emscripten-example
Executing C libraries from Python using WASM and Emscripten
https://github.com/wiwichips/pythonmonkey-emscripten-example
Last synced: 2 days ago
JSON representation
Executing C libraries from Python using WASM and Emscripten
- Host: GitHub
- URL: https://github.com/wiwichips/pythonmonkey-emscripten-example
- Owner: wiwichips
- Created: 2023-07-22T14:39:42.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-08-05T15:34:53.000Z (over 1 year ago)
- Last Synced: 2024-10-17T18:43:26.938Z (20 days ago)
- Language: Python
- Size: 2.93 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# PythonMonkey Emscripten Example
This example will demonstrate using [Emscripten](https://emscripten.org/) to compile a C library to webassembly and loading it from Python using [PytyhonMonkey](https://pythonmonkey.io/).
PythonMonkey is a Python library for executing JavaScript and WebAssembly from Python. Check it out on GitHub: https://github.com/Distributive-Network/PythonMonkey
In this example the following C code will be executed from Python:
```c
#includeEMSCRIPTEN_KEEPALIVE
int add(int a, int b) {
return a + b;
}
``````python
print(my_c_lib.add(1,2)) # this outputs 3
```## Installation
Install Emscripten https://emscripten.org/docs/getting_started/downloads.html
Install Python with a minimum version of 3.8.
Install PythonMonkey using pip: `$ pip install pythonmonkey`
## Build and Run
Compile the code using emcc
`$ emcc adder.c -s WASM=1 -s SIDE_MODULE=1 -o adder.wasm`Run the python program:
`$ python3 main.py`