Release of Brython 3.9, an implementation 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 web browser side, allowing the use of Python instead of JavaScript for web script development. The project code is written in Python and is distributed under the BSD license. The new release is notable for ensuring compatibility with Python 3.9 and updating the standard library.

By connecting libraries brython.js and brython_stdlib.js, a web developer can to use use Python to define the logic of website operations on the client side, applying Python instead of JavaScript. To include Python code on pages, the tag with the mime type 'text/python' is used. Both embedding the code on the page and loading external scripts () are allowed. The script provides complete 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 such as Bootstrap3, LESS, and SASS is provided.

Executing Python code from blocks <script> производится через предварительную компиляцию этого когда, выполняемую обработчиком Brython после загрузки страницы. Компиляция инициируется при помощи вызова функции brython(), например через добавление «<body onload="»brython()»">». На основе Python кода формируется представление на языке JavaScript, которое затем выполняется штатным JavaScript-движком браузера (для сравнения, проект PyPy.js offers a compiled interpreter of CPython in asm.js for executing Python code in the browser, while Skulpt implements a JavaScript interpreter).

The final performance of most operations in Python scripts embedded in web pages is close to CPython performance. The delay occurs only at the compilation stage, but to eliminate it, the option to load precompiled JavaScript code is provided, which is used to speed up the loading of the standard library (Brython provides toolkit for creating JavaScript libraries based on Python modules).

<script type=»text/python»>

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'

</script>

Source: opennet.ru

Buy reliable website hosting with DDoS protection, VPS VDS servers 🔥 Buy reliable website hosting with DDoS protection, VPS VDS servers | ProHoster