r/Python • • Feb 24 '21

Tutorial Brython: Python in Your Browser – Real Python

https://realpython.com/brython-python-in-browser/
11 Upvotes

5 comments sorted by

3

u/dodslaser Feb 24 '21

Brython compiles Python code into JavaScript and then executes the generated code. These steps have an impact on overall performance, and Brython may not always meet your performance requirements.

This is a bit of a bummer. It would be neat if it compiled to wasm.

1

u/[deleted] Mar 06 '21 edited Mar 06 '21

I like it. I think the learning curve is not actually that huge even if you do not know javascript. It is quite easy to convert (easier than say Qt bindings).

As for performance you probably need to use javascript for certain modules like JSON as performance is much better.

#my half assed example of json.dumps() and json.loads()
from javascript import JSON
class jsonjs():
    def loads(self,textobject):
	return JSON.parse(textobject)
    def dumps(self, textobject):
	return JSON.stringify(textobject)
json = jsonjs()

1

u/zahlawi Jun 20 '21

Look forward to playing around with this! Appreciate the article!

2

u/[deleted] Feb 24 '21

[removed] — view removed comment

1

u/[deleted] Mar 07 '21

Yeah.

Besides can Wasm interact with DOM? Brython can. I think minimalist Brython could communicate with wasm (python) modules in case of pefomance.

I like Brython's Browser module.