1. pyodide
The Pyodide JavaScript package
pyodide
Package: pyodide
Created by: pyodide
Last modified: Sun, 31 Mar 2024 14:07:44 GMT
Version: 0.25.1
License: Apache-2.0
Downloads: 152,420
Repository: https://github.com/pyodide/pyodide

Install

npm install pyodide
yarn add pyodide

Pyodide JavaScript package

npm

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
Loading distutils
Loaded distutils
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();
Loading distutils
Loaded distutils
undefined
> await pyodide.runPythonAsync("1+1");
2

Details

The JavaScript code in this package is responsible for the following tasks:

  1. 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
  2. Loads the CPython interpreter and the core/pyodide emscripten application
    which embeds the interpreter.
  3. Injects the js/pyodide JavaScript API into sys.modules. This is the
    final runtime dependency for core/pyodide & py/pyodide, so after this step
    the interpreter is fully up and running.

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code