Convert Figma logo to code with AI

pyodide logopyodide

Pyodide is a Python distribution for the browser and Node.js based on WebAssembly

11,967
809
11,967
543

Top Related Projects

11,971

Pyodide is a Python distribution for the browser and Node.js based on WebAssembly

Wasm powered Jupyter running in the browser 💡

Emscripten: An LLVM-to-WebAssembly Compiler

6,357

Brython (Browser Python) is an implementation of Python 3 running in the browser

17,824

Try PyScript: https://pyscript.com Examples: https://tinyurl.com/pyscript-examples Community: https://discord.gg/HxvBtukrg2

Quick Overview

Pyodide is a Python distribution that runs in the browser, allowing you to run Python and its scientific stack (NumPy, Pandas, Matplotlib, etc.) directly in the web browser. It is built on top of WebAssembly, a low-level, high-performance language that can be executed in modern web browsers.

Pros

  • Browser-based Python: Pyodide enables you to run Python and its scientific ecosystem directly in the web browser, without the need for a separate server-side component.
  • Cross-platform: Pyodide is designed to work across a wide range of modern web browsers, making it a cross-platform solution for running Python in the browser.
  • Extensive library support: Pyodide includes a wide range of popular Python libraries, including NumPy, Pandas, Matplotlib, and more, allowing you to leverage the full power of the Python ecosystem.
  • Interactive development: Pyodide supports interactive development, allowing you to write, test, and debug Python code directly in the browser.

Cons

  • Performance limitations: While Pyodide is designed to be performant, it may not be as fast as native Python, especially for computationally intensive tasks, due to the overhead of running in a web browser.
  • Limited access to system resources: As a browser-based solution, Pyodide has limited access to system resources, such as the file system, which may restrict certain use cases.
  • Dependency on web browsers: Pyodide is entirely dependent on the capabilities of modern web browsers, and its functionality may be limited by browser compatibility issues.
  • Startup time: Loading Pyodide and its dependencies in the browser can take some time, which may impact the user experience for certain use cases.

Code Examples

Here are a few examples of how you can use Pyodide:

  1. Importing and using NumPy:
import numpy as np

x = np.array([1, 2, 3, 4, 5])
print(x * 2)
  1. Plotting with Matplotlib:
import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 10, 100)
y = np.sin(x)

plt.plot(x, y)
plt.show()
  1. Interacting with the DOM:
from pyodide.http import pyfetch

async def get_weather(city):
    response = await pyfetch(f'https://api.openweathermap.org/data/2.5/weather?q={city}&appid=YOUR_API_KEY')
    data = await response.json()
    return data['weather'][0]['description']

city = 'New York'
weather = await get_weather(city)
print(f'The weather in {city} is {weather}')

Getting Started

To get started with Pyodide, you can follow these steps:

  1. Include the Pyodide script in your HTML file:
<script src="https://cdn.jsdelivr.net/pyodide/v0.21.3/full/pyodide.js"></script>
  1. Initialize Pyodide and load the necessary packages:
async function main() {
  await loadPyodide();
  await pyodide.loadPackage(['numpy', 'matplotlib']);
}

main();
  1. Now you can start using Pyodide in your JavaScript code:
const code = `
import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0, 10, 100)
y = np.sin(x)

plt.plot(x, y)
plt.show()
`;

await pyodide.runPython(code);

This will execute the provided Python code and display a sine wave plot in the browser.

Competitor Comparisons

11,971

Pyodide is a Python distribution for the browser and Node.js based on WebAssembly

Pros of Pyodide

  • Main repository for the Pyodide project
  • Contains core implementation and documentation
  • Actively maintained with regular updates and releases

Cons of Pyodide

  • Larger codebase, potentially more complex to navigate
  • May include experimental features or work-in-progress code

Code Comparison

Not applicable in this case, as both repositories refer to the same project. The main Pyodide repository contains the actual codebase, while the other might be used for different purposes (e.g., issues, discussions, or documentation).

Additional Notes

The comparison between pyodide/pyodide and pyodide/pyodide> is not meaningful, as they appear to be the same repository. The ">" character at the end of the second name might be a typo or formatting issue. Pyodide is a project that brings the Python runtime to the browser using WebAssembly. It allows running Python code in web browsers, enabling the use of Python libraries and scientific computing tools in web applications.

For the most up-to-date and accurate information about Pyodide, it's best to refer to the official repository at https://github.com/pyodide/pyodide.

Wasm powered Jupyter running in the browser 💡

Pros of JupyterLite

  • Provides a full Jupyter notebook environment in the browser
  • Includes a file browser and terminal emulator
  • Supports multiple kernels (Python, JavaScript, R)

Cons of JupyterLite

  • Larger download size and initial load time
  • Limited to browser-based execution, which may impact performance
  • Fewer supported packages compared to Pyodide

Code Comparison

JupyterLite (Python kernel):

from ipywidgets import interact
import matplotlib.pyplot as plt

def plot_sine(frequency):
    x = np.linspace(0, 10, 1000)
    y = np.sin(frequency * x)
    plt.plot(x, y)
    plt.show()

interact(plot_sine, frequency=(1, 10))

Pyodide:

import micropip
await micropip.install('matplotlib')
import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 10, 1000)
y = np.sin(2 * x)
plt.plot(x, y)
plt.show()

Both projects aim to bring Python to the browser, but JupyterLite offers a more comprehensive notebook environment, while Pyodide focuses on providing a Python runtime with access to scientific computing libraries. JupyterLite is better suited for interactive data analysis and visualization, while Pyodide offers more flexibility for integrating Python into web applications.

Emscripten: An LLVM-to-WebAssembly Compiler

Pros of Emscripten

  • Broader language support: Compiles C and C++ to WebAssembly, not limited to Python
  • More mature and established project with a larger community
  • Offers more low-level control and optimization options

Cons of Emscripten

  • Steeper learning curve, especially for developers not familiar with C/C++
  • Requires more setup and configuration compared to Pyodide
  • Less seamless integration with existing Python ecosystems

Code Comparison

Pyodide (Python):

import numpy as np
arr = np.array([1, 2, 3, 4, 5])
result = np.sum(arr)

Emscripten (C++):

#include <emscripten.h>
#include <vector>
#include <numeric>

EMSCRIPTEN_KEEPALIVE
int sumArray() {
    std::vector<int> arr = {1, 2, 3, 4, 5};
    return std::accumulate(arr.begin(), arr.end(), 0);
}

While Pyodide allows for direct use of Python and its libraries in the browser, Emscripten requires compiling C++ code to WebAssembly. Pyodide offers a more familiar environment for Python developers, while Emscripten provides greater flexibility and performance potential for C/C++ projects.

6,357

Brython (Browser Python) is an implementation of Python 3 running in the browser

Pros of Brython

  • Lighter weight and faster initial load times
  • Simpler setup process for basic web applications
  • Native browser integration without additional runtime

Cons of Brython

  • Limited access to Python standard library and third-party packages
  • Performance can be slower for complex computations
  • Less compatibility with existing Python codebases

Code Comparison

Brython:

from browser import document, alert

def greet(event):
    alert("Hello, World!")

document["mybutton"].bind("click", greet)

Pyodide:

import js

def greet(event):
    js.alert("Hello, World!")

js.document.getElementById("mybutton").addEventListener("click", greet)

Both Brython and Pyodide aim to bring Python to the web browser, but they take different approaches. Brython translates Python code directly to JavaScript, while Pyodide uses WebAssembly to run CPython in the browser. This fundamental difference impacts their performance, compatibility, and use cases.

Pyodide offers a more complete Python environment, including access to scientific libraries like NumPy and Pandas. It's better suited for complex applications and data analysis in the browser. Brython, on the other hand, is more lightweight and easier to integrate into simple web applications, making it a good choice for small-scale projects or educational purposes.

17,824

Try PyScript: https://pyscript.com Examples: https://tinyurl.com/pyscript-examples Community: https://discord.gg/HxvBtukrg2

Pros of PyScript

  • Simpler syntax and easier to use for beginners
  • Built-in UI components and widgets for interactive web applications
  • Tighter integration with HTML, allowing inline Python code

Cons of PyScript

  • Less mature and stable compared to Pyodide
  • More limited access to Python packages and modules
  • Potentially slower performance for complex computations

Code Comparison

PyScript:

<py-script>
print("Hello, World!")
</py-script>

Pyodide:

pyodide.runPython(`
    print("Hello, World!")
`)

Additional Notes

Pyodide serves as the foundation for PyScript, providing the core functionality of running Python in the browser. PyScript builds upon this foundation, offering a more user-friendly interface and additional features for web development.

While Pyodide offers more flexibility and control over the Python environment, PyScript simplifies the process of integrating Python into web pages, making it more accessible for developers with less experience in JavaScript or web development.

Both projects are actively developed and have their own strengths, with Pyodide being more suitable for advanced use cases and PyScript being more approachable for quick prototyping and simple web applications.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

NPM Latest Release PyPI Latest Release Build Status Documentation Status

Pyodide is a Python distribution for the browser and Node.js based on WebAssembly.

What is Pyodide?

Pyodide is a port of CPython to WebAssembly/Emscripten.

Pyodide makes it possible to install and run Python packages in the browser with micropip. Any pure Python package with a wheel available on PyPi is supported. Many packages with C extensions have also been ported for use with Pyodide. These include many general-purpose packages such as regex, PyYAML, lxml and scientific Python packages including NumPy, pandas, SciPy, Matplotlib, and scikit-learn.

Pyodide comes with a robust Javascript ⟺ Python foreign function interface so that you can freely mix these two languages in your code with minimal friction. This includes full support for error handling, async/await, and much more.

When used inside a browser, Python has full access to the Web APIs.

Try Pyodide (no installation needed)

Try Pyodide in a REPL directly in your browser. For further information, see the documentation.

Getting Started

Pyodide offers three different ways to get started depending on your needs and technical resources. These include:

  • Use a hosted distribution of Pyodide: see the Getting Started documentation.
  • Download a version of Pyodide from the releases page and serve it with a web server.
  • Build Pyodide from source
    • Build natively with make: primarily for Linux users who want to experiment or contribute back to the project.
    • Use a Docker image: recommended for Windows and macOS users and for Linux users who prefer a Debian-based Docker image with the dependencies already installed.

History

Pyodide was created in 2018 by Michael Droettboom at Mozilla as part of the Iodide project. Iodide is an experimental web-based notebook environment for literate scientific computing and communication.

Iodide is no longer maintained. If you want to use Pyodide in an interactive client-side notebook, see Pyodide notebook environments.

Contributing

Please view the contributing guide for tips on filing issues, making changes, and submitting pull requests. Pyodide is an independent and community-driven open-source project. The decision-making process is outlined in the Project governance.

Communication

License

Pyodide uses the Mozilla Public License Version 2.0.

NPM DownloadsLast 30 Days