The developers of Anaconda, a leading Python distribution, have recently announced PyScript, a Python that runs in the browser.

PyScript

According to the official description, PyScript is a development framework that provides developers with the ability to write Python code embedded in standard HTML, call JavaScript libraries using Python, and create Python web applications.

PyScript aims to provide a “first-class” programming language with consistent stylization rules, more expressiveness, and easier learning.

PyScript example code

1
2
3
<py-script>
"Hello World"
</py-script>
1
<py-script src="/my_own_file.py"></py-script>
1
2
3
4
5
6
  <py-env>
- bokeh
- numpy
- paths:
  - /utils.py
  </py-env>

PyScript core features

  • Python in the browser: drop-in content enabled, external file hosting (based on the Pyodide project), and application hosting that does not rely on server-side configuration
  • Python ecology: Provides popular Python and scientific computing packages (e.g. numpy, pandas, scikit-learn, etc.)
  • Python with JavaScript: Two-way communication between Python and JavaScript objects and namespaces
  • Environment Management: Developers can define which packages and files to bring in for running page code
  • Visual Application Development: Developers can use off-the-shelf UI components such as buttons, containers, text boxes, etc.
  • Flexible Framework: Developers can use it to create and share new pluggable and extensible components directly in Python

PyScript Goals

  • Provide a clean and simple API
  • Support standard HTML
  • Extend HTML to read stable and reliable custom components
  • Provide a pluggable and extensible component system

PyScript is built on Pyodide, which consists of a CPython 3.8 interpreter compiled to WebAssembly that allows Python to be run in a web browser. Pyodide can install any Python package from PyPi. Pyodide also includes an external function interface that exposes Python packages to JavaScript and the browser UI, including the DOM, to Python.

Pyodide

For more information on how PyScript works see: https://engineering.anaconda.com/2022/04/welcome-pyscript.html

pyscript

PyScript is currently in alpha testing, download and install at: https://pyscript.net/