If you are a python developer, and thinking that how cool if I can write my python code directly into HTML as all the Javascript developers do. Well, there is good news for all the Python developers. Here is the step by step tutorial for how to run python in HTML using PyScript. Show In a keynote speech at PyCon US 2022, Anaconda company’s CEO Peter Wang revealed a new project named PyScript. Which is a javascript framework. It allows us to create Python applications in web browsers. It will allow us to embed Python code directly into HTML files. Just like we use Javascript code in our HTML files. Contents Important things about Pyscript
1. Let’s Create our first program with PyscriptYou can download the alpha release of PyScript on pyscript.net. We’ll use the CDN of one stylesheet and one script in our HTML file. Add below CDNs to your HTML <head>.
Our Hello world program will look something like this:
When you run this HTML file into your browser, it will print Hello World. Something like this: 2. Print Current Date Time
In the above example, we are using python’s DateTime library for current DateTime. 3. Bokeh Chart with PyscriptLet’s create a chart to display the number of fruits sells during a month.
When you run this code, you will see a chart like; As you see how easily we can create a graph into our HTML file only. There is no need to create complex components to display a chart like this. That’s how simply you can use Pyscript to run python in HTML. ConclusionThis project is still in the alpha stage, so maybe we can see many more new things in the upcoming days. Pyscript looks very promising for python developers, but there might be a lot of security issues. Also, we are running Python libraries into the browser, so execution time is also high. All these concerns might be resolved in upcoming releases. Comment down your thoughts about this new technology. |