py-in-browser
v1.2.0
Published
This package is a python--web-assembler built for the web using Pyodide
Downloads
2
Readme
py-in-browser
This package is a python--web-assembler built for the web using Pyodide
Features
- Write and execute Python code directly in the browser.
- Utilizes Pyodide to run Python code using a WebAssembly build of the CPython interpreter.
- Provides a simple and interactive development environment for Python.
Getting Started
Installation
Install the package using npm:
npm install py-in-browser
Add cross origin policy in headers:
'Cross-Origin-Opener-Policy': 'same-origin','Cross-Origin-Embedder-Policy': 'require-corp','Cross-Origin-Resource-Policy': 'same-site',
Import the package into your JavaScript/TypeScript code:
const { initializeWorker, runcode } = require("py-in-browser");
Initialize the worker(initialization of pyodide):
initializeWorker(callbackfunction);
Execute Python code:
const code = print('hello world')
Call the runcode method:
runcode(code);
Define the callback function to handle the output from Python code execution:
function callbackfunction(text){
let output += text;
console.log(output);
}