Limitations of the "file" protocol

Frequently asked questions

Syntax, keywords and built-in functions

Standard distribution

import implementation

Brython packages

Browser interface

Introduction - DOM API
Creating a document
Accessing elements
Attributes, properties and methods

Mouse events
Keyboard events
Focus events
Drag events

Query string

Using Javascript objects and libraries

Brython-specific built-in modules




Working with Brython

Options of function brython()
Testing and debugging
Deploying an application


Hello world !
Insert content in an element
HTML markup (bold,italic...)
HTML table
Bind and unbind events
Handle options in a SELECT
Drag and drop
Get the content of an element
Read the content of a file
Store objects locally
Example of onmouseover

No installation

You can use Brython without having to install anything, just by including the Brython scripts from a CDN:

<script src="">
<script src="">


<script src="">
<script src="">

Local installation

To install Brython locally:

  • if your PC has CPython and pip, install the package brython by

    pip install brython

The package installs a client program brython-cli (same as python -m brython).

then in an empty directory run

brython-cli --install

  • if you can't use this method, go to the releases page on Github, select the latest version, download and unzip

In both cases the directory has the following files :

  • brython.js : the Brython engine, to include in the HTML page
  • brython_stdlib.js : groups all the modules and packages of the part of the Python standard library supported by Brython
  • demo.html : a page with a few examples of how to use Brython for client-side development

brython.js includes very often used modules : browser, browser.html, javascript.

If your application uses modules of the standard distribution, you need to include brython_stdlib.js besides brython.js:

<script type="text/javascript" src="brython.js"></script>
<script type="text/javascript" src="brython_stdlib.js"></script>


When a new version of Brython is published, the update is done by the usual command:

pip install brython --upgrade

In the application directory, you can then update the Brython files (brython.js and brython_stdlib.js) by:

brython-cli --update

Installing a CPython package

A CPython package installed by pip can be installed in a Brython application by the command --add_package <package name>.

For example:

pip install attrs
brython-cli --add_package attrs

All the files in the package must of course be usable by Brython; this excludes files written in C for instance.

Other commands

-- modules

creates an application-specific distribution, to replace brython_stdlib.js by a smaller file. See section import.

-- make_dist

generate a CPython package, suitable for distribution by PyPI, to install a Brython application. See section Deploying a Brython application

-- make_package

generates a "Brython package", allowing to distribute a module or a package in a very straightforward way. See section Packages Brython

Web server

The HTML files can be opened in the browser, but it is recommended to start a web server in the application directory.

The most straightforward is to use the module http.server in CPython standard distribution:

python -m http.server

The default port is 8000. To choose another port:

python -m http.server 8001

You can then access the pages by entering http://localhost:8001/demo.html in the browser address bar.