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

Interactions with Javascript

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

Execution options
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
 

Limitations of the "file" protocol

The HTML files stored in a computer can be loaded in the browser in two different ways:

  • by the File / Open browser menu: in this case the browser uses the "file" protocol (the address in the address bar starts with file://)
  • by launching a local web server (for instance the one provided by Python standard distribution: python -m http.server) and entering the file address in the browser address bar (for instance localhost:8000//app.html). The protocol is "http" (or "https")

These options are mostly the same, but the "file" protocol comes with a few limitations:

  • external scripts cannot be loaded with the syntax <script type="text/python" src="test.py"></script>
  • it is not possible to import modules or packages located in the same directory as the application
  • files cannot be opened and read with open()

The reason is that these features rely on Ajax calls to get the modules / packages source code, or the file contents; and browsers do not allow making Ajax calls when the protocol is "file".

With this protocol, it is always possible to import the modules in the standard library if the file brython_stdlib.js is loaded in the page, as well as Brython packages, or the modules bundled in file brython_modules.js created by the command brython-cli modules (cf. section import implementation).