Ever since JavaScript became the default language for web browsers, the demand for technology that could translate to it has been unending. Assemblers and compilers, two subsets of translators, are the technology used to perform this conversion from another programming language to JavaScript.
With Python becoming the most common "first language" for developers due to the simple syntax, the demand for a Python compiler is great. Coupled with its powerful back-end capabilities, it is clear why programmers are looking to use it to build an entire application.
It's been a dream of many programmers to use Python instead of JavaScript for front-end coding, but there is a simple unmovable obstacle. Browsers all support JavaScript, but not Python”
Marc Nealer, Practical Brython
My original intent in writing this piece was to delve into three prominent Python-to-JavaScript compilers: Brython, Transcrypt, and Pyodide. I began with Brython because it had the most accessible documentation. As I explored it more deeply, the focus of this post naturally shifted. The length got away from me, and rather than attempt to summarize all three superficially, I decided to give Brython the spotlight it deserved.
Unlike Transcrypt—which compiles Python to JavaScript ahead of time and is maintained collaboratively with no single project owner—or Pyodide, a WebAssembly-based solution that loads a full Python runtime in the browser, Brython takes a different approach. It inserts Python code directly into HTML and interprets it at runtime, providing a uniquely accessible way to write Python for the browser.
Brython
With a name meaning "Browser Python", it is fitting for Brython to top many lists of these compilers. Straightforward and Python focused, Brython describes itself as an implementation of Python3 running in the browser. Brython is especially appealing to Python developers because it supports the full functionality of Python. Since version 3.8.0, Brython has updated to match the newest version of Python with the same version number. It interfaces directly with the DOM by inserting Python code directly inside HTML5 with script tags.
<span class="na">type="text/python">
...
A full example of a simple HTML page running Python might look like this:
<span class="na">src="/path/to/brython.js">
<span class="na">type="text/python">
from browser import bind, document, alert
@bind(document['mybutton'], 'click')
def echo(event):
alert(document["zone"].value)
id="zone"> id="mybutton">click !
Enter fullscreen mode
Exit fullscreen mode
Events cannot be triggered by a script in the HTML. Handling is done inside the Brython code by binding event listener functions to HTML elements. Programmers have the option to bind by id, class, tag, or attribute.
from browser import document, bind
# get the element from the document
el = document["mybutton"]
#set up a function to be called
def button_clicked(evt):
print("mybutton clicked")
#bind the element to the function so it is run when the event occurs
el.bind("click", button_clicked)
Enter fullscreen mode
Exit fullscreen mode
Pros
Pure Python: No need to dive deep into JavaScript.
Direct DOM Access: Using Python instead of JS syntax.
Great for Learning: Excellent for Python learners exploring the browser environment.
Cons
Performance: Because Brython interprets code at runtime, load times are slower than precompiled tools.
Limited Ecosystem: It doesn’t support many popular Python packages.
Still Need HTML/CSS: Brython replaces JavaScript, not the rest of the frontend stack.
Quick Glance at Transcrypt and Pyodide
Just to highlight how Brython compares:Transcrypt compiles Python to JavaScript before the code ever hits the browser. It offers better performance, access to JS libraries, and even offers React integration.Pyodide brings the full CPython runtime into the browser via WebAssembly. It is incredibly powerful for scientific computing but can be heavy and slow to load.
Final Thoughts
Brython offers a unique approach for developers who want to stay in Python while working on the frontend. It may not be ideal for every production use case, but for rapid prototyping, educational projects, or Python-first workflows, it’s a surprisingly fun and effective tool.
Sources
Brython
Transcrypt Github
Pyodide Official Site
Marc Nealer, Practical Brython