DEV Community


Posted on

Python in the browser

You can use Python on the web, instead of Javascript.
Yes, really.

There's a project named Brython: "A Python 3 implementation for client-side web programming".

So how does it work:

Step 1: Include Brython

<script type="text/javascript" src="/src/brython.js"></script>

Step 2: Write your code, say

<body onload="brython(1)">

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

def echo(ev):
    alert("Hello {} !".format(document["zone"].value))

document["test"].bind("click", echo)
<p>Your name is : <input id="zone" autocomplete="off">
<button id="test">clic !</button>

Step 3: Demo

More resources,

Learn python and demos

Top comments (9)

sebastiannielsen profile image

But why?
What are the advantages?

lesha profile image
lesha πŸŸ¨β¬›οΈ

it's fun

sebastiannielsen profile image

I mean, sure, I do like writing in Python more than JavaScript ... but other than that, what advantages are there?

Thread Thread
lesha profile image
lesha πŸŸ¨β¬›οΈ • Edited

Mostly syntactic sugar i guess. I'd love to be able to use list/dict comprehensions, named arguments, but most of all, format strings.

garador profile image

I personally find it appealing since I'm learning Python. Wouldn't take it to production, tough...

cardiox12 profile image

In theory that's very cool, but I tested it for an extension project where I needed python,
that was very painful to use for the moment, because brython doesn't support some functions related to DOM, etc.
So I hope this will get better and better.
Cool module tho. :)

mdor profile image
Marco Antonio Dominguez

Has this any benefit? I mean, it seems like this adds a new complexity layer to any project without any benefit, everything which is a wrapper or non native become slower and non maintainable in a long term.
Up to now this just push a personal preference without even consider the disadvantages of the tech debt it will generate.

dowenb profile image
Ben Dowen

Mind, blown. Thank you.

genta profile image
Fabio Russo • Edited

JS is a magic language for browser/DOM/frontend stuff... it's useless to use another language (made with other kind of stuff in mind).

But, hey, It looks cool anyway.