AI-Aided Coding
On average, how much time do you think you save per week by an AI-powered coding assistant such as GitHub Copilot or JetBrains AI Assistant?
I don’t use an AI coding assistant.
Up to 1 hour/week
1-3 hours
3-5 hours
5-8 hours
More than 8 hours
I don’t save any time, yet!
Frontend Development / Open Source / Software Development

4 Developer Takeaways from a Pyscript Demo

Pyscript works with or without JavaScript and offers the Python ecosystem inside HTML, explains a senior developer advocate from Anaconda.
Sep 30th, 2022 11:34am by
Featued image for: 4 Developer Takeaways from a Pyscript Demo
Image via Shutterstock

“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 pyscript.”

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?

Maggio spent a good deal of time really drilling into what Pyscript is and how it differs or does not differ from JavaScript and HTML — more on that below. As for the basics — what is Pyscript — he explained that it’s a client-side technology that doesn’t require a server. Strictly speaking, it’s implemented by a few lines of code in HTML to call Pyscript from Anaconda. You can download it or add some code to your page:

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.

“It’s a fantastic methodology to have Python finally working alongside JavaScript to do lots of things,” Maggio explained. “It’s an environment management system. It’s a flexible framework that allows you to create pluggable components.”

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.”

The syntax highlighting within the Pyscript helps to make it easier to reuse code because, as he put it, “It would become cumbersome to have HTML, JavaScript and Python altogether and Python not highlighted properly.”

3. Pyscript Is Not a Javascript Replacement

Pyscript is a single-page application (SPA); from a more technical perspective it is just written in TypeScript, Maggio said. It’s not meant to be a JavaScript killer, he stressed.

“What’s the deal here? What’s going on exactly?” he said. “Well, Pyscript allows the use of Python in the browser to build interactive web apps, something you would normally do at the moment with JavaScript. Pyscript allows you to work with or without JavaScript.”

In fact, some of the demos he used in the webinar involved interacting directly with JavaScript, while others did not.

It’s also more than Python, he added.

“First off, a selling feature is Python in the browser; but it’s not just Python, the language in the browser, it is more like the Python ecosystem in the browser,” he said. “It’s Python with JavaScript.“

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 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:

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.

If developers are bothered by the mixture of presentation and programming, bear in mind that, for better or worse, it’s the same thing that happens using JavaScript, he said.

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.

Group Created with Sketch.
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.