Frequently asked questions

Syntax, keywords and built-in functions

Standard distribution

import implementation

Brython packages

Browser interface

Brython-specific built-in modules

Working with Brython



module javascript

The module javascript allows interaction with the objects defined in Javascript programs and libraries present in the same page as the Brython program.

Returns the Javascript code generated by Brython from the Python source code src.

Returns the Brython object matching the value of the Javascript object this. It may be useful when using Javascript frameworks, eg when a callback function uses the value of this.

The module also allows using objects defined by the Javascript language. Please refer to the documentation of these objects.

javascript.Date doc
Constructor of date / time objects.

from javascript import Date

date =, 6, 10)

javascript.JSON doc
Object to convert to and from JSON objects. It exposes two functions:

stringify: serialize simple objects (dictionaries, lists, tuples, integers, reals, strings)

parse: conversion of a JSON-formatted string into a simple object

javascript.Math doc
Object for mathematical functions and constants.

javascript.Number doc
Constructor for objects of type "number".

javascript.RegExp doc
Constructor of "regular expression" objects, using the Javascript-specific syntax, which doesn't fully match that of Python. The method exec() of instances of this class can be applied to Python strings:

from javascript import RegExp

re ="^test(\d+)$")

javascript.String doc
Constructor of Javascript objects of type "string". Must be used to call methods that accept Javascript regular expressions as parameters:

from javascript import RegExp, String

re ="^test(\d+)$")