pyodide

esm cjs
The Pyodide JavaScript package
Version 0.28.0 License MPL-2.0
Keywords
pythonwebassembly
INSTALL
Type:
Version:
- Static
- Latest Patch
- Latest Minor
- Latest Major
- 0.28.0
- 0.27.7
- 0.27.6
- 0.27.5
- 0.27.4
- 0.27.3
- 0.27.2
- 0.27.1
- 0.27.0
- 0.26.4
- 0.26.3
- 0.26.2
- 0.26.1
- 0.26.0
- 0.25.1
- 0.25.0
- 0.24.1
- 0.24.0
- 0.23.4
- 0.23.3
- 0.23.2
- 0.23.1
- 0.23.0
- 0.22.1
- 0.22.0
- 0.21.3
- 0.21.2
- 0.21.1
- 0.21.0
- 0.20.0
- 0.19.1
- 0.19.0
- 0.18.2
- 0.18.1
- 0.18.0
- 0.1.1
- 0.1.0
- 0.28.0-alpha.3
- 0.28.0-alpha.2
- 0.28.0-alpha.1
- 0.27.0-alpha.2
- 0.26.0-dev.0
- 0.26.0-alpha.6
- 0.26.0-alpha.5
- 0.26.0-alpha.4
- 0.26.0-alpha.3
- 0.26.0-alpha.2
- 0.26.0-alpha.1
- 0.25.0-alpha.2
- 0.25.0-alpha.1
- 0.24.0-alpha.1
- 0.23.0-alpha.1
- 0.22.0-alpha.3
- 0.22.0-alpha.2
- 0.22.0-alpha.1
- 0.21.0-alpha.3
- 0.21.0-alpha.2
- 0.21.0-alpha.1
- 0.20.1-alpha.2
- 0.20.1-alpha.1
- 0.20.0-alpha.1
- 0.19.0-alpha.1
- 0.18.0-alpha.1
- 0.18.0-alpha.0
Pyodide JavaScript package
Usage
Download and extract Pyodide packages from Github
releases
(pyodide-build-*.tar.bz2
). The version of the release needs to match exactly the version of this package.
Then you can load Pyodide in Node.js as follows,
// hello_python.js
const { loadPyodide } = require("pyodide");
async function hello_python() {
let pyodide = await loadPyodide({
indexURL: "<pyodide artifacts folder>",
});
return pyodide.runPythonAsync("1+1");
}
hello_python().then((result) => {
console.log("Python says that 1+1 =", result);
});
$ node hello_python.js
Python says that 1+1= 2
Or you can use the REPL. To start the Node.js REPL with support for top level
await, use node --experimental-repl-await
:
$ node --experimental-repl-await
Welcome to Node.js v18.5.0.
Type ".help" for more information.
> const { loadPyodide } = require("pyodide");
undefined
> let pyodide = await loadPyodide();
undefined
> await pyodide.runPythonAsync("1+1");
2
Details
The JavaScript code in this package is responsible for the following tasks:
- Defines the public JavaScript API
- Package loading code to allow loading of other Python packages.
- Can load micropip to bootstrap loading of pure Python wheels
- Loads the CPython interpreter and the core/pyodide emscripten application which embeds the interpreter.
- Injects the
js/pyodide
JavaScript API intosys.modules
. This is the final runtime dependency forcore/pyodide
&py/pyodide
, so after this step the interpreter is fully up and running.