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
