Brython (Browser Python) is an implementation of Python 3 running in the browser.
Here is a simple example of an HTML page running Python:
<html>
<head>
<script src="/brython.js"></script>
</head>
<body onload="brython()">
<script type="text/python">
from browser import document, alert
def echo(ev):
alert(document["zone"].value)
document['mybutton'].bind('click',echo)
</script>
<input id="zone"><button id="mybutton">click !</button>
</body>
</html>
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">
.
Brython supports most of the syntax of Python 3, including comprehensions, generators, metaclasses, imports, etc. and many modules of the CPython distribution.
It includes libraries to interact with DOM elements and events, and with existing Javascript libraries such as jQuery, 3D, Highcharts, Raphael etc.
In the Releases section, load the latest version of the Brython site mirror, unzip it and start the built-in web server server.py
. Point your browser to http://localhost:8000 and click on "site" : you access a clone of the Brython site with an online editor, a console similar to the CPython interpreter, a gallery with many examples and a comprehensive documentation.
Once you are familiar with the examples, create a new folder "app" at the same level as "site" and create a file "index.html" with the HTML example above. Point the browser to http://localhost:8000/app to see the result.
If you want to test Brython online you can visit the editor or the console.
There is a gallery of examples where you can see simple and advanced examples using vanilla Brython or interacting with other javascript libraries.
Documentation is available on the official site. You can read the docs in English, French, Spanish and Portuguese. The most updated docs usually are the English version so if you want to be up-to-date, please, use that version.
There is a main mail list in english. Also, you can find mail list in other languages but the activity is very low and it is recommended to use the main one in English.
If you find a bug/issue or do you want to see a new feature in Brython, please, open a new issue.