PyScript, Will it Replace Javascript?

 


What is PyScript

Want to make a website, but don't like using Javascript.

About... there are still other programming languages.

We have been using Python for a long time to create websites. However, Python's role on the web is mostly as a backend.

This means that Python only runs on the server side. Meanwhile, on the client side (web browser) most still use Javascript.

But don't worry...

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 .

PyScript Architecture
source: anaconda.cloud

We have been able to use WebAssembly for a long time to run programs from 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 compile-free.

All we have to do is write or embed the Python code in HTML with tags <py-script>, then the program will run automatically.

Example:

<html>
    ...
    <py-script> print('Now you can!') </py-script>
</html>

It's like writing Javascript code in HTML.

So easy.. 😯

Brython has actually tried this method , but they don't seem to use WebAssembly.

The Early Rise of PyScript

Originally appeared in April 2022. You can check @pyscript_dev's first Tweet on April 3, 2022.

Deliberately tweeted on the 3rd... so it wouldn't be mistaken for April Fool's.

Then at the PyCon US 2022 event, Anaconda CEO Peter Wang was a speaker there and brought up the topic of PyScript.

pycon us 2022

PyScript itself was created by the Anaconda team including Peter Wang.

Then it was widely discussed on the internet and lots of memes about PyScript emerged.

meme pyscript

Some say Javascript will die because of PyScript.

There are also those who say: it's impossible, because Javascript itself cannot be defeated for web matters.

Which one will prove to be true, we'll see in the future. 😄

Try PyScript

So that you don't get curious, let's just try it ourselves.

First of all, we have to add PyScript in HTML like this:

<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>

As usual, this code 👆 is written inside the tag <head>.

Then, we just create a tag <py-script>within the tag <body>that contains the Python code.

<py-script> print('Hello PyScript!') </py-script>

So the result is:

hello world pyscript

The results of the code execution will not be displayed immediately. There is a behind-the-scenes process that takes place.

First, the browser will download a runtime to run the Python code. This took quite a long time, because the file size was quite large.

On the internet connection I use, it takes me 3 minutes to open and run it.

resource pyscript

This will provide a bad experience for users, because of the long load time.

Now we are required to create a website that can be opened in less than 10 seconds.

Maybe using PyScript to create a web will be less suitable. But let's try another use case.

This time I will try to run the Mario game from the code examples provided in the PyScript repository .

The result:

Super Mario example

I can't play the game yet, it's just stuck appearing like this.

Maybe there is something wrong in the way I tried.

Hmm.. 🤔

The Future of PyScript

Because it's still an alpha version, I can't say anything. Maybe in the future there will be new updates and better optimization.

Or maybe in the future PyScript will support other languages.

PytScript
source: anaconda.cloud

So we can not only write Python in the tag <py-script>, but also C, C++, Rust, R, Go, and so on.

The final word..

That's my brief review of PyScript.

If you are interested in trying it, you can stop by the repository or the official website at pyscript.net .

Currently Javascript is the most ideal programming language used on the Web.

Currently, PyScript has not been able to beat Javascript. But we don't know what the future holds.

Do you think PyScript will be able to compete and beat Javascript?

Post a Comment

Previous Post Next Post