These languages are known for their flexibility, and they have become the go-to choices for developing web applications, though they also carry the drawback of having older formats.
However, there is a newer development in the coding world – “PyScript”.
Have you ever heard of it? No? Well then,
Peter Wang, the CEO and co-founder of Anaconda, Inc., revealed it during his keynote speech at PyCon US 2022 that – It is Python inside HTML, a whole-new framework which will enable the users to create Python applications using in browser HTML interface.
It is a better alternative to Emscripten, Pyodide, WASM, and other cutting-edge web technologies which were used earlier in development.
Following are the objectives-
Along with helping in specific genres, Pyscript helps data scientists in various conditions. For example, Data scientists frequently create models but are unable to make them representable to stakeholders.
With this scripting language, they will be able to make the most of their talents and cognitive processes and because most models and charts lack an appropriate user interface, it will give targeted audiences a window to consume them.
PyScript provides standardized style rules, increased expressiveness, and simplicity of learning. Besides that, let’s take a look at what else this language explores-
Writing websites with Python is now feasible thanks to a technique called Web Assembly.
After its initial release in 2017, WebAssembly swiftly attained official status with the World Wide Web Consortium (W3C) by 2019. It contains a.wat text format language that can be read by humans, which is then translated into a binary.wasm format that browsers can read.
We can now create code in any language, compile it to WebAssembly, and then run it in a web browser thanks to this.
A WebAssembly-based Python distribution for the browser and Node.js is called Pyodide. With this, we can use micropip to install and run Python packages in the browser. For usage with Pyodide, several programs with C extensions have also been migrated. Numerous general-purpose Python packages, such as NumPy, pandas, SciPy, Matplotlib, and Scikit-learn, as well as RegEx, PyYAML, and lxml are included.
Emscripten is a full-featured WebAssembly compiler tool-chain that uses LLVM, with an emphasis on performance, size, and the Web platform.
Pyodide is the base of PyScript, and it is a WebAssembly/Emscripten version of CPython. Micropip-based Python packages may be installed and used in browsers thanks to Pyodide. It employs a binary.wasm format that can be read by browsers after being converted from a human-readable.wat text format language.
You can download the alpha release of PyScript on pyscript.net.
For reference, all HTML files that use PyScript must have a link to these:
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
PyScript allows you to write Python in HTML using the following components:
py-env– Defines the Python packages needed to run your Python code.
py-script– Part of the HTML file where you write your Python code.
py-repl– Creates a REPL component that evaluates the code user enters and displays the result.
You will, however, concentrate on the browser APIs in this section.
The following tech stack diagram shows Emscripten, an open-source compiler tool chain which make possible to generate WebAssembly from any portable C/C++ source.
The only limitation at this point is that we can only use libraries that Pyodide supports now while using PyScript.
To build a webpage, we need to know about HTML and CSS.
Let’s start with a basic example of printing “Hello world” by defining the HTML structure for webpage-
Fortunately, end users don’t have to fully grasp what’s going on in the background, other than for some security reasons. However, more languages will eventually be supported, according to the contemporary advancements in technology world.
BeforePyScript, running and carrying out Python operations on the web wasn’t simple. Anyone interested in utilizing Python on the web will find this to be a fantastic tool, despite being still in its infancy.
PyScript will indeed prove to be a head-turning evolution in the world of scripting languages.
Thanks for reading the blog!
Hoping for you to find it insightful! 😊