Python has long been able to be used to create the web. However, Python's role on the web is mostly as a backend.
This means that Python is only run on the server side. While on the client side (web browser), most still use Javascript.
But take it easy.
Is there a new technology that can make Python run in a web browser?
What's that?
pyscript.
What is PyScript?
PyScript is a new technology for running Python in the browser. The PyScript behind it uses Pyodie and WebAssembly technologies.
anaconda.cloud
We have been able to use WebAssembly for a long time to run programs in any programming language in a web browser.
The important thing is that it can be compiled into WebAssembly (wasm), then it will be able to run in the browser.
However, the method offered by PyScript is without compilation.
The program will automatically run if we just write or embed the Python code in HTML with the <py-script> tag.
Example:
<py-script>print('Now you can!')</py-script> It's like writing JavaScript code in HTML.
So easy.
This method has actually been tried by Brython, but they don't seem to use WebAssembly.
The Beginning of PyScript
Originally appeared in April 2022. You can check @pyscript_dev's first Tweet on April 03, 2022.
I accidentally tweeted on the 3rd so it wouldn't be mistaken for April Fool's Day.
Then at PyCon US 2022, Anaconda CEO Peter Wang was the speaker there and brought up the topic of PyScript.
2022, PythonThe Anaconda team, including Peter Wang, created PyScript itself.
Then there was a lot of talk on the internet, and a lot of memes about PyScript popped up.
pyscript memes Some say Javascript will die because of PyScript.
There are also those who say it's impossible because Javascript itself can't be beat for web business.
Which one will prove true, we'll see in the future.
Try PyScript
Let's not be curious, let's just try it ourselves.
First of all, we have to add PyScript to the HTML like this:
As usual, this code is written inside the <head> tag.
Then, we just create a <py-script> tag inside the <body> tag which contains the Python code.

Post a Comment
Post a Comment