The release of Brython 3.10 (Browser Python) has been announced, implementing the Python 3 programming language for execution in the web browser, allowing developers to use Python instead of JavaScript for scripting in the Web. The project's code is written in Python and is distributed under a BSD license.
By including the libraries brython.js and brython_stdlib.js, a web developer can use Python to define site logic on the client side, applying Python instead of JavaScript. To include Python code on web pages, the tag with the mime type 'text/python' is used. Both inline code and external script loading are allowed (). The script provides full access to DOM elements and events. In addition to access to the standard Python library, specialized libraries for interacting with the DOM and JavaScript libraries such as jQuery, D3, Highcharts, and Raphael are offered. Support for CSS frameworks Bootstrap3, LESS, and SASS is also provided.
Executing Python code from blocks <script> производится через предварительную компиляцию этого кода, выполняемую обработчиком Brython после загрузки страницы. Компиляция инициируется при помощи вызова функции brython(), например через добавление «<body onload="»brython()»">». На основе Python-кода формируется представление на языке JavaScript, которое затем выполняется штатным JavaScript-движком браузера (для сравнения, проект PyPy.js предлагает для выполнения Python-кода в браузере скомпилированный в asm.js интерпретатор CPython, а Skulpt реализует интерпретатор на JavaScript).
The overall performance of most operations in embedded Python scripts for web pages is close to that of CPython. There is a delay only at the compilation stage, but to eliminate this, there is the option to load pre-compiled JavaScript code, which is used to accelerate the loading of the standard library (Brython provides a toolkit for creating JavaScript libraries based on Python modules).
The new release is notable for ensuring compatibility with Python 3.10, including support for the match/case pattern matching operators. This version also introduces an initial implementation of the Abstract Syntax Tree (AST) for the Python language, which can subsequently be used for generating JavaScript code from a universal AST.
Source: opennet.ru
