The release of Brython 3.15.0 (Browser Python) is now available, implementing the Python 3 programming language for web browsers, allowing the use of Python instead of JavaScript for developing scripts for the web. The Brython 3.15 branch ensures compatibility with CPython 3.15 and implements most of the new features of this release, including deferred module imports, frozendict and sentinel types, and the operators ‘*’ and ‘**’ for unpacking list comprehensions. The project's code is written in Python and is distributed under the BSD license.
By connecting the brython.js and brython_stdlib.js libraries, web developers can use Python to define site logic on the client side, applying Python instead of JavaScript. To include Python code on pages, the <script> tag with a mime type of 'text/python' is used. Both embedding code directly on 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 access to the Python standard library, specialized libraries are offered for interaction with the DOM and JavaScript libraries such as jQuery, D3, Highcharts, and Raphael. CSS frameworks Bootstrap3, LESS, and SASS are supported.
Executing Python code from blocks <script> производится через предварительную компиляцию этого кода, выполняемую обработчиком Brython после загрузки страницы. Компиляция инициируется при помощи вызова функции brython(), например через добавление «<body onload="»brython()»">». На основе Python-кода формируется представление на языке JavaScript, которое затем выполняется штатным JavaScript-движком браузера.
The overall performance of most operations in Python scripts embedded in web pages is close to that of CPython. Latency only occurs at the compilation stage, but there is an option to load pre-compiled JavaScript code, which is applied to speed up the loading of the standard library (Brython provides tools for creating JavaScript libraries based on Python modules).
Source: opennet.ru
