Linux News

Brython 3.10 Release, Python Implementation for Web Browsers

Pinterest LinkedIn Tumblr

Submitted by A release of the project Brython 3.10 (Browser Python) with a web browser-side implementation of the Python 3 programming language, allowing you to use Python instead of JavaScript to develop scripts for the Web. The project code is written in Python and is distributed under the BSD license.

By connecting the brython.js and brython_stdlib.js libraries , a web developer can use Python to define the logic of the client-side site, using Python instead of JavaScript. To include Python code on pages, use the <script> tag with the “text / python” mime type. Both embedding code into the page and loading external scripts (<script type = “text / python” src = “test.py”>) are allowed. Full access to DOM elements and events is provided from the script. In addition to accessing the Python standard library, specialized libraries are offered for interacting with the DOM and JavaScript libraries such as jQuery, D3, Highcharts, and Raphael. The use of CSS frameworks Bootstrap3, LESS and SASS is supported.

Execution of Python code from <script> blocks is done through pre-compilation of this code by the Brython engine after the page has loaded. Compilation is initiated by calling the brython () function, for example by adding “<body onload =” brython () “>”. Based on the Python code, a JavaScript representation is formed, which is then executed by the standard JavaScript engine of the browser (for comparison, the project PyPy.js offers a CPython interpreter compiled in asm.js for executing Python code in the browser, and Skulpt implements the interpreter in JavaScript) …

The final performance of most operations in Python scripts embedded in web pages is close to that of CPython. The delay occurs only at the compilation stage, but to eliminate it, the ability to load pre-compiled JavaScript code is provided, which is used to speed up the loading of the standard library (Brython provides tools for creating JavaScript libraries based on Python modules).

The new release is notable for its compatibility with Python 3.10 , including support for operators for pattern matching (match / case). The new version also offers an initial implementation of an abstract syntax tree (AST, Abstract Syntax Tree) for the Python language, which can later be used to generate JavaScript code from a universal AST.

Write A Comment