Python 3 in the browser
npm install brythonbrython
=======
Brython (Browser Python) is an implementation of Python 3 running in the
browser, with an interface to the DOM elements and events.
Here is a simple example of an HTML page running Python:
``html
`
brython()
To use Brython, all there is to do is:
1. Load the script brython.js.
2. Run the function on page load, like
.
3. Write Python code inside tags
The previous code will allow you to use raw python code, but if you import
modules from the standard library you have to load a single javascript file
with the available stdlib:
`html
src="https://cdn.jsdelivr.net/npm/brython@3.10.4/brython_stdlib.js">
`
jsDelivr supports version ranges, so if you want the latest of the
3.10.x versions:
`html
src="https://cdn.jsdelivr.net/npm/brython@3.10/brython.min.js">
src="https://cdn.jsdelivr.net/npm/brython@3.10/brython_stdlib.js">
`
or the latest of the 3.x.y versions:
`html
src="https://cdn.jsdelivr.net/npm/brython@3/brython.min.js">
src="https://cdn.jsdelivr.net/npm/brython@3/brython_stdlib.js">
`
If you want to use the latest development version, you can load these scripts
instead:
`html
`
Local install
-------------
To install Brython locally, if you have a CPython distribution with pip :
`bash
pip install brython
`
then create a new directory and run
`bash
brython-cli --install
``