Introduction

Installation

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

Events
Mouse events
Keyboard events
Focus events
Drag events

Query string

Using Javascript objects and libraries

Brython-specific built-in modules

browser
browser.aio
browser.ajax
browser.html
browser.local_storage
browser.markdown
browser.object_storage
browser.session_storage
browser.svg
browser.template
browser.timer
browser.webcomponent
browser.websocket
browser.worker

Widgets
browser.widgets.dialog
browser.widgets.menu

interpreter
javascript

Working with Brython

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

Cookbook

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
 

Options of function brython()

To run the Python scripts in the page, you must call the function brython() on page load.

<body onload="brython([options])">

options can be an integer, in this case it is the debug level :

  • 0 (default) : no debugging. Use this when the application is debugged, it slightly speeds up execution
  • 1 : error messages are printed in the browser console (or to the output stream specified by sys.stderr)
  • 2 : the translation of Python code into Javascript code is printed in the console
  • 10 : the translation of Python code and of the imported modules is printed in the console

options can be a Javascript object, its keys can be

  • debug : debug level (see above)
  • cache : if set to true, the Ajax calls to import modules, load external scripts by <script src="foo.py"> or read files with open() use the browser cache. Defaults to false.
  • static_stdlib_import : boolean, indicates if, in order to import modules or packages from the standard library, the static mapping table in the script stdlib_paths.js should be used. Defaults to true
  • pythonpath : a list of paths where imported modules should be searched
  • ids : by default, the function brython() runs all the scripts in the page. This option specifies a list of element identifiers (tag attribute id) whose text content must be run as Python code
  • ipy_id": same as ids*. See brythonmagic for more information
  • indexedDB : specifies if the program can use the indexedDB database to store a compiled version of the modules located in brython_stdlib.js or brython_modules.js. Defaults to true.

Example of brython options usage:

brython({debug:1, ids:['hello']})

will run the content of the element with id "hello" with debug level 1