Brython (Browser Python) is an implementation of Python 3 running in the browser, with an interface to the DOM elements and events.
Here is a simple example of an HTML page running Python:
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
Brython supports the syntax of Python 3, including comprehensions, generators, metaclasses, imports, etc. and many modules of the CPython distribution.
Zero install !
The most simple way to get started, without anything to install, is to use the distribution available online through jsDelivr. You can choose the latest stable release :
If you want to use the latest development version, you can load these scripts instead:
To install Brython locally, if you have a CPython distribution with
pip install brython
then create a new directory and run
python -m brython --install
or by loading the latest version of the Brython zip file from the releases page.
In both cases, the distribution includes brython.js (the core Brython engine) and brython_stdlib.js (a bundle of all the files in the standard distribution).
It also includes the page demo.html that shows a few examples of how you can interact with a web page using Python as the scripting language : create new elements, access and modify existing elements, create graphics, animations, send Ajax requests, etc.
Test Brython online
If you want to test Brython online you can visit the following:
Gallery of examples
You can start by reading the official Brython tutorial.
The most updated docs usually are the English and French versions so if you want to be up-to-date, please, use these versions.
Curious about how Brython works ?
A tutorial explains how to build Android applications with Brython.
Community (questions, feedback, issues, new features, ...)
You can subscribe and post to the mailing list.
If you find a bug/issue or do you want to see a new feature in Brython, please, open a new issue.
If you want to contribute to Brython, please read the contributing guide.
- BrowserStack for providing an access to their online testing environment.