{"library":"pyodide","title":"Pyodide: Python in the Browser & Node.js","description":"Pyodide is an open-source project that compiles the CPython interpreter to WebAssembly, enabling the full execution of Python directly within web browsers and Node.js environments without requiring a server backend. Its current stable release is 0.29.3, with frequent patch and minor updates; a significant version change to 314.0.0a1 signals alignment with upcoming Python 3.14 releases and a revised ABI stabilization strategy. Key differentiators include seamless bidirectional interoperability between JavaScript and Python, comprehensive support for a vast array of popular scientific Python libraries (such as NumPy, Pandas, and Matplotlib), and a lightweight package manager (`micropip`) that allows dynamic installation of pure Python wheels from PyPI. This enables advanced client-side data processing, interactive visualizations, and powerful educational tools to run entirely within the browser, significantly expanding Python's reach in web development.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install pyodide"],"cli":null},"imports":["import { loadPyodide } from 'pyodide';\n// Or for older Node.js/CJS:\n// const { loadPyodide } = require('pyodide');","import type { PyodideInterface } from 'pyodide';","await pyodide.runPython(`\n  import sys\n  print('Hello from Python!', file=sys.stderr)\n`);","await pyodide.loadPackage('numpy');","await pyodide.loadPackage('micropip');\nconst micropip = pyodide.pyimport('micropip');\nawait micropip.install('matplotlib');"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { loadPyodide } from 'pyodide';\n\nasync function main() {\n  console.log('Initializing Pyodide...');\n  const pyodide = await loadPyodide({\n    indexURL: 'https://cdn.jsdelivr.net/pyodide/v0.25.0/full/' // Always pin the version!\n  });\n  console.log('Pyodide initialized.');\n\n  // Redirect Python stdout/stderr to JS console\n  pyodide.setStdout((text) => console.log('PY_STDOUT:', text));\n  pyodide.setStderr((text) => console.error('PY_STDERR:', text));\n\n  // Run simple Python code\n  console.log('Running Python code...');\n  const pythonResult = await pyodide.runPython(`\n    import sys\n    print('Hello from Python!')\n    x = 10\n    y = 20\n    x + y\n  `);\n  console.log('Python computed:', pythonResult);\n\n  // Load a Python package and use it\n  console.log('Loading NumPy...');\n  await pyodide.loadPackage('numpy');\n  const numpyVersion = pyodide.runPython('import numpy; numpy.__version__');\n  console.log('NumPy version:', numpyVersion);\n\n  const jsArray = [1, 2, 3, 4, 5];\n  pyodide.globals.set('js_array', jsArray);\n\n  const pythonArrayResult = await pyodide.runPython(`\n    import numpy as np\n    py_array = np.array(js_array)\n    print(f'Python array sum: {py_array.sum()}')\n    py_array.tolist()\n  `);\n  console.log('Python processed array:', pythonArrayResult);\n\n  // Clean up PyProxy objects if necessary (important for preventing memory leaks)\n  pyodide.destroy();\n  console.log('Pyodide instance destroyed.');\n}\n\nmain().catch(err => {\n  console.error('An error occurred:', err);\n});","lang":"typescript","description":"This quickstart demonstrates how to load Pyodide, execute basic Python code, install a scientific package like NumPy, and facilitate data exchange between JavaScript and Python, all within a browser environment.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}