Frequently asked questions

Syntax, keywords and built-in functions

Standard distribution

import implementation

Browser interface

Brython-specific built-in modules

Working with Brython



First installation

To install Brython :

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

    pip install brython

then in an empty directory run

    python -m brython --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 et brython_stdlib.js) by:

python -m brython --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
python -m brython --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

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.