What is Brython?
Brython is a way to use python instead of javascript for browsers.
However, the only way to implement brython on web pages is to source it from a JavaScript file. The convenience is able to write python script inside a HTML file or to have a python program (.PY file) executed by HTML controls.
How do I use Brython?
Taken from the github repository of Brython:
To use Brython, all there is to do is .
- load the script brython.js.
- run the function brython() on page load.
- write Python code inside tags
<script type="text/python">.
Where to download Brython:
https://github.com/PierreQuentel/brython/releases
There are two different files:
The latest version of brython is the necessary javascript files to code Python into a html file.
The site mirror file contains a clone of the brython.info website that includes documentation and an online script editor console (similar to CPython).
How does Brython work?
Python scripts are converted to JavaScript code, which might explain why it compiles 3-5 times slower. In the FAQ (http://brython.info/doc/en/index.html) , the developers explain circumstances concerning run-time:
- the time to translate Python into Javascript, on the fly in the browser. To give an idea, the module datetime (2130 lines of Python code) is parsed and converted to Javascript in 0,5 second on an ordinary PC
- JavaScript code generated by Brython must be compliant with the specifications of Python, including the dynamic nature of the search attributes, which leads to unoptimized Javascript code