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

Published project release Brython 3.9 (Browser Python) 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 spreads under the BSD license. The new release is notable for its compatibility with Python 3.9 and updating the standard library.

By including libraries brython.js ΠΈ brython_stdlib.js, a web developer can use the Python language to define the logic of the site on the client side, using Python instead of JavaScript. To include Python code on pages, use the tag с mime-Ρ‚ΠΈΠΏΠΎΠΌ Β«text/pythonΒ». ДопускаСтся ΠΊΠ°ΠΊ встраиваниС ΠΊΠΎΠ΄Π° Π½Π° страницу, Ρ‚Π°ΠΊ ΠΈ Π·Π°Π³Ρ€ΡƒΠ·ΠΊΠ° Π²Π½Π΅ΡˆΠ½ΠΈΡ… скриптов (). Из скрипта прСдоставляСтся ΠΏΠΎΠ»Π½Ρ‹ΠΉ доступ ΠΊ элСмСнтам ΠΈ событиям DOM.
In addition to accessing the Python standard library, there are specialized libraries 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.

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

The overall performance of most operations in Python scripts embedded in web pages close to CPython performance. 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 tools to create JavaScript libraries based on Python modules).

import time
import math

from browser import document
import browser.timer

content = document["content"]

...

canvas = content.select_one(".clock")

if hasattr(canvas, 'getContext'):
ctx = canvas.getContext("2d")

browser.timer.set_interval(set_clock, 100)
show_hours()
else:
content.select_one('.navig_zone').html = "canvas is not supported"

Source: opennet.ru

Add a comment