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(event): 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, like
- Write Python code inside tags
<script type="text/python">or linking it.
Brython supports most of the syntax of Python 3, including comprehensions, generators, metaclasses, imports, etc. and many modules of the CPython distribution.
In the Releases section, load the latest version of the Brython site mirror,
unzip it and start the built-in web server
Point your browser to http://localhost:8000/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.
git clone https://github.com/brython-dev/brython.git cd brython python server.py
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.
Put ALL of them at the top of the file Sorted and Grouped together by the type of import:
- Future, if any, eg:
from __future__ import braces
- Python Standard Library, eg:
- Third Party, if any, eg:
from twisted import log
- Current Python Project, if any, eg:
from clients import Client
- Explicitly Local, if any, eg:
from . import blah
- Custom, if any, eg: imports inside
try: ... except:...blocks
Do I have to do it Manually?, one by one?. No... Please use:
pip install isort isort file.py
- By having the imports Alphabetically Sorted and Grouped allows better code, less error prone, eg. Unused imports, duplicated imports, etc.
Test Brython online
If you want to test Brython online you can visit the following:
Gallery of examples
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.
Questions, feedback, issues, new features...
If you find a bug/issue or do you want to see a new feature in Brython, please, open a new issue.
Theres a Brython Community on Google Plus.
Brython KanBan of Tickets Whats Brython Team working on ?
Throughput Graph: Statistics about our work...