On April 30, 2022, Peter Wang, CEO of Anaconda, introduced PyScript, a new framework that brings the Python language into HTML and the web browser. The framework allows developers to create Python applications directly in the browser without requiring a server backend.
<html>
<head>
...
# Include PyScript CSS and JS
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
</head>
...
<py-script>
print("Hello world!")
</py-script>
...
</html>
The PyScript project offers many important features and benefits beyond the ability to author Python in HTML documents:
numpy
, matplotlib
, and scikit-learn
, all in the browser.PyScript has been billed as a lot of things such as "programming for everyone", a JavaScript killer (it's not), or a replacement for Jupiter notebooks (again, it's not). We would like to focus on some less often mentioned benefits of PyScript for practitioners, data science teams, academics, and business leaders.
After many years of chaos and growing pains including the browser wars, the dot com bubble, and the development of Web 2.0, the web has stabilized into a rock-solid platform. The web is itself cross-platform and backwards compatible. Sites that ran 10 years ago will still run today. While the PyScript project is still new, it is also quickly maturing and stabilizing. One might argue that, in the near future, PyScript will become the most reliable way to create and distribute data-centric projects.
PyScript is based on the Pyodide project. Pyodide was built to include a large number of packages covering many of the disciplines for which Python is often used:
numpy
, pandas
, sympy
, mpmath
astropy
, biopython
matplotlib
, bokeh
, imageio
, asciitree
scikit-learn
beautifulsoup4
, soupsieve
See Packages built in Pyodide for more.
Since PyScript projects are simply HTML documents, sharing complex applications becomes far more simple than the sharing of a traditional project. Want to show off your work to a colleague? You can email the file or drop it into Slack. You can run a local server (python -m http.server
) and use something like ngrok to send a public URL to your friend. No spinning up an environment or virtual machine.
Ready to publish your project? Deployment is as easy has hosting a static website. No devops, no Linux administration, no Docker or Kubernetes. If you can host a simple "Hello World" web page, you can publish a PyScript project.
By bringing Python into the browser, the "how did they do that" of a data-centric app becomes as accessible as clicking "View Source" in the browser. Before YouTube, blogs, and bootcamps, early web practitioners, such as myself, learned our craft by viewing the source of other people's work. In fact, I would personally credit the ability to view the source of any website as a key contributor to the rapid growth of the early web. The ability to view the source of PyScript projects is huge.