IntroductionInstallationLimitations of the "file" protocolFrequently asked questionsSyntax, keywords and built-in functionsStandard distributionimport implementationBrython packagesBrowser 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 BrythonCookbook |
No installationYou can use Brython without having to install anything, just by including the Brython scripts from a CDN:<script src="https://cdn.jsdelivr.net/npm/brython@3/brython.min.js"> </script> <script src="https://cdn.jsdelivr.net/npm/brython@3/brython_stdlib.js"> </script>The minor version can be specified with brython@3.11 and the micro version
with brython@3.11.0 .
Brython is also available with cdnjs:
<script src="https://cdnjs.cloudflare.com/ajax/libs/brython/3.11.0/brython.min.js"> </script> <script src="https://cdnjs.cloudflare.com/ajax/libs/brython/3.11.0/brython_stdlib.min.js"> </script> Local installationTo install Brython locally:
brython-cli (same as python -m brython ).
then in an empty directory runbrython-cli install
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> UpdatesWhen a new version of Brython is published, the update is done by the usual command:pip install brython --upgradeIn the application directory, you can then update the Brython files (brython.js and brython_stdlib.js) by: brython-cli update Installing a CPython packageA CPython package installed bypip can be installed in a Brython application
by the command add_package <package name> .
For example:pip install attrs brython-cli add_package attrsAll the files in the package must of course be usable by Brython; this excludes files written in C for instance. Other commandsmake_modules
creates an application-specific distribution, to replace
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 -- version
prints the Brython version Web serverThe 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.serverThe default port is 8000. To choose another port: python -m http.server 8001You can then access the pages by entering http://localhost:8001/demo.html in the browser address bar. |