Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
B

brython

> 编程语言
Open source

Brython (Browser Python) is an implementation of Python 3 running in the browser

6.6K stars0 likes2 views
WebsiteGitHub

About

Brython (Browser Python) is an implementation of Python 3 running in the browser

brython

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:

xml
<html>

    <head>
        <script src="/path/to/brython.js"></script>
    </head>

    <body>

        <script type="text/python">
        from browser import bind, document, alert

        @bind(document['mybutton'], 'click')
        def echo(event):
            alert(document["zone"].value)
        </script>

        <input id="zone"><button id="mybutton">click !</button>

    </body>

</html>

To use Brython, all there is to do is:

  1. Load the script brython.js.
  2. Write Python code inside tags <script type="text/python">.

Main features

Brython supports the syntax of Python 3, and the modules of the CPython distribution written in Python, except for the features that are not relevant in the browser context (writing on disk for instance).

Since version 3.8.0, Brython implements the Python version of the same major / minor version number.

It includes libraries to interact with DOM elements and events, and with existing Javascript libraries such as jQuery, D3, Highcharts, Raphael etc. It supports the latest specs of HTML5/CSS3, and can use CSS Frameworks like Bootstrap3, LESS, SASS etc.

Getting started

Zero install !

The most simple way to get started, without anything to install, is to use the distribution available online through jsDelivr. You can choose the latest stable release :

xml
<script src="https://cdn.jsdelivr.net/npm/[email protected]/brython.min.js">
</script>

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:

xml
<script src="https://cdn.jsdelivr.net/npm/[email protected]/brython_stdlib.js">
</script>

jsDelivr supports version ranges, so if you want the latest of the 3.14.x versions:

xml
<script src="https://cdn.jsdelivr.net/npm/[email protected]/brython.min.js">
</script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/brython_stdlib.js">
</script>

or the latest of the 3.x.y versions:

xml
<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>

If you want to use the latest development version, you can load these scripts instead:

xml
<script src="https://raw.githack.com/brython-dev/brython/master/www/src/brython.js"
        crossorigin="anonymous">
</script>
<script src="https://raw.githack.com/brython-dev/brython/master/www/src/brython_stdlib.js"
        crossorigin="anonymous">
</script>

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

or by loading the latest version of the Brython zip file from the releases page.

In both cases, the distribution includes brython.js (the core Brython engine) and brython_stdlib.js (a bundle of all the files in the standard distribution).

It also includes the page demo.html that shows a few examples of how you can interact with a web page using Python as the scripting language : create new elements, access and modify existing elements, create graphics, animations, send Ajax requests, etc.

Test Brython online

If you want to test Brython online you can visit the following:

  • Editor
  • Console

Gallery of examples

There is a gallery of examples where you can see simple and advanced examples using vanilla Brython or interacting with Javascript libraries.

Documentation

You can start by reading the official Brython tutorial.

Full documentation is available on the official site. You can read the docs in English and French.

Curious about how Brython works ?

A tutorial explains how to build Android applications with Brython.

You can also Ask Brython Guru, it is a Brython-focused AI to answer your questions.

Community (questions, feedback, issues, new features, ...)

You can subscribe and post to the mailing list.

If you find a bug/issue or do you want to see a new feature in Brython, please, open a new issue.

If you want to contribute to Brython, please read the contributing guide.

Thank you

  • BrowserStack for providing an access to their online testing environment.

Issues· 148 open

View all issuesOpen on GitHub
  • #3020

    Raising an exception inside an exec on compiled code fails

    Updated Sep 23, 2026
  • #3019

    'import f from m' syntax inside of an exec on compiled code fails

    Updated Sep 23, 2026
  • #2939

    Recursing to the recursion limit in a Web Worker overflows the Javascript stack instead of raising RecursionError

    Updated Sep 10, 2026
  • #1938

    No stubs for brython for PyCharm - crucial to make it popular (coding efficiency - heart of Python).

    Updated Sep 4, 2026
  • #2910

    The zlib.compress() function crashes when the data size is greater than 102

    Updated Aug 3, 2026
  • #2656

    Can we run external libraries like PyTorch with Brython?

    Updated Jul 30, 2026
  • #2643

    aio.gather() raises RuntimeWarnings with standard use

    Updated Jul 9, 2026
  • #2733

    [Feature Request] An easy way to run latest `git` code

    Updated Jun 23, 2026
  • #2692

    Brython crashes on reference to a cross-origin window

    Updated May 24, 2026
  • #2689

    `removeEventListener` does not work when `useCapture` is set and leads to `TypeError: missing callback for event ended`

    Updated May 17, 2026

> Tags

Python

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 24, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言