A new project from Anaconda delivers the Python runtime in a web page, via a single JS include, and with access to many popular Python packages. Anaconda, makers of the Python distribution for scientific computing, announced at PyCon US 2022 the PyScript project — an in-browser, single-include way to run Python scripts in HTML pages as easily as JavaScript itself. Traditionally, Python could interact with JavaScript or a web page only by running as an application server that returned HTML and JavaScript. PyScript has no server component; everything runs directly in the browser. Using PyScript, useful components from both the Python and JavaScript worlds can be deployed side-by-side. In one example, the NYC taxi data demo, PyScript uses Pandas to analyze data, then generates an interactive 3D view of the data by way of JavaScript’s WebGL. IDG A PyScript demo (real-time rendering of NYC taxi activity) that uses Pandas for number crunching and JavaScript visualization libraries to provide an interactive view of the data. PyScript uses a full port of the CPython runtime to WebAssembly to run in-line Python code. You place your Python code inside <py-script> tags, and you can place its output in a selected <div>. A <py-repl> tag inserts a REPL block that allows you to input and execute code, and a <py-env> tag functions like the requirements.txt file in a repository to list needed packages. The PyScript runtime also enables many common Python packages such as the scientific libraries bundled with Anaconda—NumPy, Pandas, Scikit-learn, and many more. Demos in the PyScript repository show various ways to do this. While PyScript is still in the early stages, it already provides the ability for Python and JavaScript to interoperate—for Python to reference the DOM, for instance, or for JavaScript objects to address Python objects. PyScript also enables in-browser equivalents for many behaviors needed in a Python distribution, such as listing package requirements for a script. Earlier projects in this vein, like Pyodide (which PyScript uses as a basis for its own work), lacked PyScript’s smooth integration between JavaScript and Python, and its broad access to packages. PyScript has access to every package available through PyPI, with the commonly used Pandas and NumPy already available. However, third-party packages work best if they’re pure Python. PyScript has no mechanism yet for automatically building platform binaries for packages, although this is theoretically possible. Another obstacle is the time and bandwidth needed to download and set up all of the components needed for a given PyScript-enabled web page. The core Python runtime is about 3.4MB of WebAssembly, although it’s cached after the first load. Anaconda’s goal for PyScript, as described in a community message board post, is to make it one possible solution to the long-standing problem of packaging and deploying Python applications. It has long been difficult to take a Python script, especially one with many dependencies, and bundle it up for someone else to use as-is without the Python runtime. Related content news Wasmer WebAssembly platform now backs iOS Wasmer 5.0 release also features improved performance, a leaner codebase, and discontinued support for the Emscripten toolchain. By Paul Krill Oct 30, 2024 2 mins Mobile Development Web Development Software Development news analysis What Entrust certificate distrust means for developers Secure communications between web browsers and web servers depend on digital certificates backed by certificate authorities. What if the web browsers stop trusting your CA? By Travis Van Oct 30, 2024 9 mins Browser Security Web Development Application Security news Next.js 15 arrives with faster bundler High-performance Rust-based Turbopack bundler moves from beta to stable with the latest update of the React-based web framework. By Paul Krill Oct 24, 2024 2 mins JavaScript React Web Development feature WasmGC and the future of front-end Java development WebAssembly’s garbage collection extension makes it easier to run languages like Java on the front end. Could it be the start of a new era in web development? By Matthew Tyson Oct 16, 2024 10 mins Web Development Software Development Resources Videos