Release of Brython 3.11, implementations of the Python language for web browsers

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

By including the brython.js and brython_stdlib.js libraries, a web developer can use Python to define client-side site logic using Python instead of JavaScript. To include Python code on pages, use the tag с mime-Ρ‚ΠΈΠΏΠΎΠΌ Β«text/pythonΒ». ДопускаСтся ΠΊΠ°ΠΊ встраиваниС ΠΊΠΎΠ΄Π° Π½Π° страницу, Ρ‚Π°ΠΊ ΠΈ Π·Π°Π³Ρ€ΡƒΠ·ΠΊΠ° Π²Π½Π΅ΡˆΠ½ΠΈΡ… скриптов (). Из скрипта прСдоставляСтся ΠΏΠΎΠ»Π½Ρ‹ΠΉ доступ ΠΊ элСмСнтам ΠΈ событиям DOM. Помимо доступа ΠΊ стандартной Π±ΠΈΠ±Π»ΠΈΠΎΡ‚Π΅ΠΊΠ΅ Python ΠΏΡ€Π΅Π΄Π»Π°Π³Π°ΡŽΡ‚ΡΡ спСциализированныС Π±ΠΈΠ±Π»ΠΈΠΎΡ‚Π΅ΠΊΠΈ для взаимодСйствия с DOM ΠΈ JavaScript-Π±ΠΈΠ±Π»ΠΈΠΎΡ‚Π΅ΠΊΠ°ΠΌΠΈ, Ρ‚Π°ΠΊΠΈΠΌΠΈ ΠΊΠ°ΠΊ jQuery, D3, Highcharts ΠΈ Raphael. ΠŸΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΈΠ²Π°Π΅Ρ‚ΡΡ использованиС CSS-Ρ„Ρ€Π΅ΠΉΠΌΠ²ΠΎΡ€ΠΊΠΎΠ² Bootstrap3, LESS ΠΈ SASS.

Executing Python code from blocks производится Ρ‡Π΅Ρ€Π΅Π· ΠΏΡ€Π΅Π΄Π²Π°Ρ€ΠΈΡ‚Π΅Π»ΡŒΠ½ΡƒΡŽ ΠΊΠΎΠΌΠΏΠΈΠ»ΡΡ†ΠΈΡŽ этого ΠΊΠΎΠ΄Π°, Π²Ρ‹ΠΏΠΎΠ»Π½ΡΠ΅ΠΌΡƒΡŽ ΠΎΠ±Ρ€Π°Π±ΠΎΡ‚Ρ‡ΠΈΠΊΠΎΠΌ Brython послС Π·Π°Π³Ρ€ΡƒΠ·ΠΊΠΈ страницы. ΠšΠΎΠΌΠΏΠΈΠ»ΡΡ†ΠΈΡ инициируСтся ΠΏΡ€ΠΈ ΠΏΠΎΠΌΠΎΡ‰ΠΈ Π²Ρ‹Π·ΠΎΠ²Π° Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ brython(), Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ Ρ‡Π΅Ρ€Π΅Π· Π΄ΠΎΠ±Π°Π²Π»Π΅Π½ΠΈΠ΅ «». На основС Python-ΠΊΠΎΠ΄Π° формируСтся прСдставлСниС Π½Π° языкС JavaScript, ΠΊΠΎΡ‚ΠΎΡ€ΠΎΠ΅ Π·Π°Ρ‚Π΅ΠΌ выполняСтся ΡˆΡ‚Π°Ρ‚Π½Ρ‹ΠΌ JavaScript-Π΄Π²ΠΈΠΆΠΊΠΎΠΌ Π±Ρ€Π°ΡƒΠ·Π΅Ρ€Π° (для сравнСния, ΠΏΡ€ΠΎΠ΅ΠΊΡ‚ PyPy.js ΠΏΡ€Π΅Π΄Π»Π°Π³Π°Π΅Ρ‚ для выполнСния Python-ΠΊΠΎΠ΄Π° Π² Π±Ρ€Π°ΡƒΠ·Π΅Ρ€Π΅ скомпилированный Π² asm.js ΠΈΠ½Ρ‚Π΅Ρ€ΠΏΡ€Π΅Ρ‚Π°Ρ‚ΠΎΡ€ CPython, Π° Skulpt Ρ€Π΅Π°Π»ΠΈΠ·ΡƒΠ΅Ρ‚ ΠΈΠ½Ρ‚Π΅Ρ€ΠΏΡ€Π΅Ρ‚Π°Ρ‚ΠΎΡ€ Π½Π° JavaScript).

The overall 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 precompiled JavaScript code is provided, which is used to speed up the loading of the standard library (Brython provides a toolkit for creating JavaScript libraries based on Python modules).

The new release is notable for providing compatibility with CPython 3.11 and implementing most of the new features in this branch, including support for exception groups and the "except*" expression, detailing problematic expressions in diagnostic messages, and attaching notes to exceptions.

Source: opennet.ru

Add a comment