Member-only story
Getting Started With PyScript
Running Python on a web browser
At PyCon US 2022, the Anaconda team announced PyScript, a tool to write Python code in a web browser, similar to JavaScript. PyScript will support different languages along with Python.
For Web Developers
- Write Python in HTML.
- Build web applications in Python.
For Data Scientists
- Running Dashboards and Machine Learning Models in an HTML file.
What is PyScript?
PyScript is built on top of Pyodide, which is a port of CPython to WebAssembly/Emscripten. Now, there are a lot of new terms I presume, let's decode each one.
CPython — It implements Python, which we download from Python. C programming is used for writing python’s interpreter, hence the name CPython. Now, Pyodide acts as an interface between PyScript and WebAssembly/Emscripten.
WebAssembly/Emscripten — WebAssembly is a core component in building websites nowadays. It was released in 2017 and was quickly adopted by the W3C standard in 2019. It compiles code from other languages into WebAssembly format, which is supported in web browsers. Emscripten is a compiler toolchain to WebAssembly, using LLVM, with a special focus on speed, size, and the Web platform.
😲 oh Man !!! there are a lot of exchanges happening between the languages to render websites on a web browser.
Installation
There is no installation required to use PyScript 😇. While writing your web pages or HTML file, we can just import the relevant files from the PyScript website.
<link rel=”stylesheet” href=”https://pyscript.net/alpha/pyscript.css" />
<script defer src=”https://pyscript.net/alpha/pyscript.js"></script>
🤩 Sample Code
<html>
<head>
<link rel=”stylesheet” href=”https://pyscript.net/alpha/pyscript.css" />
<script defer src=”https://pyscript.net/alpha/pyscript.js"></script>
</head>
<body>
<py-script>
print(“Let’s…