Anaconda Brings Python to the Browser With PyScript

Anaconda over the weekend took the wrap off its PyScript project that allows data scientists and programmers to embed Python programs in HTML pages and execute them within the browser.

Traditionally, Python runs on an application server and returns results in HTML and rendered by the browser. An alternative is a development platform such as the one Anaconda offers.

Python from a browser

The new offering announced at PyCon US 2022 allows Python to be run within the Web browser for greater flexibility.

“PyScript is a framework that allows users to create rich Python applications in the browser using a mix of Python with standard HTML. PyScript aims to give users a first-class programming language that has consistent styling rules, is more expressive, and is easier to learn,” explained Fabio Pliger, principal software architect at Anaconda in a blog post.

PyScript acts as a wrapper around the Pyodide project, which loads the CPython interpreter as a WebAssembly browser module, explained Bleeping Computer. This means that users no longer need to use a different syntax but can run Python code pasted into a local HTML page.

With PyScript developers can:

  • Use Python and JavaScript together with bi-directional communication between them.
  • Directly access popular Python packages commonly used by data scientists, including NumPy, Pandas, and scikit-learn.
  • Develop visual application using curated UI components such as buttons, containers, text boxes, and others.
  • Define packages and files to include within the page.

Developers can also load a code editor directly using the py-repl tag to input code and execute it immediately – no server-side configuration needed.

To be clear, PyScript has no mechanism yet for building platform binaries. However, it is a compelling offering for data scientists looking to quickly test out a Python code snippet or to quickly process some data on a machine lacking their normal assortment of data science tools.

“[We] believed that the browser would be a great platform that we could adapt to achieve our goals of providing a reliable, accessible, and fun experience for PyScript users. The browser works everywhere (from laptops, tablets, to phones), and is secure, powerful, and stable,” wrote Pliger.

Examples of PyScript in action can be found here, while PyScript itself can be downloaded from GitHub here.

Image credit: iStockphoto/filizbbr