TABLE OF CONTENTS
1. Overview2. Introduction to PyScript3. PyScript Architecture Core Elements PyScript Architecture5. PyScript Components6. Conclusion7. CloudThat 8. FAQs
Overview
Python has been used in web development as a backend language. We need to depend on Python software that is hosted on the server in order to use Python in web apps. However, we can now run python code directly from the HTML file.
Are you a Python developer? Or a data scientist. Are you jealous of JavaScript-coders who create complex browser-based websites? Wouldn’t it be amazing if we could create websites in Python? Surprisingly, Anaconda CEO Peter Wang introduced PyScript, a new technology that allows users to write Python and other languages directly in their browsers, at PyCon US 2022.
PyScript: Introduction
PyScript is a JavaScript framework that allows you to build Python applications in your browser. This is true, as any JavaScript developer, you can embed Python code directly in HTML files. This project allows us execute Python directly in our browser.
PyScript’s concept can be described as follows: Data scientists can use their chosen language to create websites based upon their models as long as they understand HTML.
HTML files that contain PyScript can be hosted in the AWS cloud S3 bucket. This makes the HTML file dynamic rather than static. This Pyscript makes HTML files more robust by rendering dynamic HTML pages using the AWS Lambda services.
PyScript’s Core Elements
Python in the browser: This allows you to host drop-in content and external files without needing server-side settings
Python Ecosystem: Use NumPy and pandas, scikit–learn and other popular Python or scientific stack packages
Environment management: Users can choose which files and packages should be included so that the page code can run
PyScript Architecture:
PyScript is written using Pyodide (a CPython/WebAssembly Bridge).
CPython, a fast Python implementation, was developed in both Python (and C).
WebAssembly, a low-level language, is very similar in performance to Assembly. It can be used in binary format. It is a trans piler for any Python code you create. It consists of a human-readable.wat language that is then translated into a binary.wasm format browsers can understand. It is now possible to create code in any language and compile it into WebAssembly. Then, it can be run in a web browser.
PyScript Components:
PyScript relies on three components to enable us to write Python in HTML.
py-env, a Python environment variable that specifies the Python packages needed to run your Python code, is called. This tag is placed inside Html tag. Syntax: #To declare packages you need 1 Example:
To insert Python code into HTML, we use py-script.
py-repl generates a REPL (Read-Eval-Print-Loop) component that evaluates and displays the code entered by the user. #Creates a REPL shell, where user can execute interactive python code 1 #Creates a REPL shell, where user can execute interactive python code
Example 1:
Page Titlebo