4 Developer Takeaways from a Pyscript Demo
“Wouldn’t it be cool if we could run Python in the browser,” asked Anaconda senior developer advocate Valerio Maggio during a recent webinar, “Rethinking Data Visualisation with
He proceeded to demonstrate exactly how useful Pyscript, Anacando’s new language, could be by demonstrating the code with multiple data visualization tools. But first, he offered a developer’s perspective of what he’s learned about Pyscript. Here are four takeaways from his talk:
1. What the Heck Is Pyscript, Again?
<link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
<script defer src="https://pyscript.net/latest/pyscript.js"></script>
He noted it actually has two versions at this point — Alpha, which is frozen and more stable, or you can download the latest release. Anaconda is also pinning releases. Releases follow CalVer as a versioning convention, he added.
He also addressed the why of Pyscript.
“The potential to this technology is manyfold,” he said. “In essence, Pyscript is just HTML. But to just say that Pyscript is just HTML, it’s not entirely true, isn’t it? This is slightly more powerful […] than just HTML, because Pyscript brings the whole Python ecosystem directly into the browser. And the mission of this project is [enable] programming for the 99%.“
Of course, here’s the other thing about Pyscript, he reminded the audience: Pyscript is not ready for production as it’s still being developed.
2. Pycharm Supports Pyscript
If you’d prefer IDE support before you try Pyscript, Maggio recommended PyCharm, an IDE for Python. In fact, he used it to create the presentation seen during the webinar.
“Pycharm has done a great job in supporting Pyscript syntax highlighting within the Pyscript times,” he said. “If you ask me, I would definitely recommend using PyCharm as the go-to solution to use Pyscript immediately. And to be fair, this is what I’ve been using to prepare for this presentation. It’s working perfectly.”
It’s also more than Python, he added.
4. PHP Vibes
The first time Maggio saw Pyscript, it gave him “PHP vibes,” he confessed. It was a joke, he said, but he added a best practice of PHP is to use something else. “Are we really doing the dark side here? How are we going into the direction of making Python a new PHP, which by the way, means person on page anyway, […] so we really joined the dark side.”
That made him take a more careful look at Pyscript.
“I understood that it’s completely a whole new ecosystem in front of me,” he said.”The answer is very simple [but] is actually not, because Pyscript is much much more than that — it is absolutely [in] no way related to PHP kind of technology.”
With Pyscript, developers can avoid mixing HTML and Python code if that bothers them — and it should bother them, he added.
“It’s not a good practice mixing presentation and programming logic,” he said. “In Pyscript, you can actually have the Python code separated in a separated module, you can write everything in a timer.py. In this example, I’ve imported using the auto — see the source attribute in the pyscript time. So the Pyscript enables best practice.”
He demoed the timer script:
from datetime import datetime
now = datetime.now()
It’s important to remember that Pyscript is also working within the web browser environment.
When Maggio thinks of code in HTML, he thinks of JSP technology, he acknowledged. But that requires servers and, again, Pyscript is client-side technology so no server is required and no installation is required, he noted.
His full presentation provided more information on the Pyscript architecture, which is built atop Pyodide, a spinoff of the discontinued Mozilla Iodide project, and WASM. It also featured demos with Matplotlib, Seaborn, Bokeh, Panel and HvPlot, NetworkX and D3.js. He’s made the slides, complete with code links, available online in — what else — Pyscript.