PyScript — Going Truly Serverless

Example Pyscript tag in HTML

I was very excited when Anaconda announced PyScript and finally got to spend a few hours tinkering. The result is a simple webpage using NMF from Scikit-Learn to perform topic modeling! That’s correct Numpy and Scikit-Learn running in a browser and finding topics from sentences entered into a textarea.

Try NMF | View Source Code

Potential to go truly serverless

So obviously serverless still involves a server somewhere in the cloud but I see PyScript as a way to go truly serverless. Functionality leveraging great Python libraries such as Scikit-Learn, Pandas, Numpy and Matplotlib that I would usually implement within an AWS Lambda, Container or EC2 can now be included in regular HTML (with an additional initial load time). I could for example build a plugin for a no/low code app builder (e.g., a visualisation recommendation system) that runs completely client side.

Caveats

PyScript is still in alpha and it was not all smooth sailing. Here are some issues I encountered:

  • There is not a lot of documentation. I mainly looked at the examples to figure out how to trigger Python from HTML and write back to HTML.
  • The default stylesheet overwrites default HTML setting eg the H1 tag padding is changed.
  • When I placed the textarea within a form tag, each time the button was clicked all libraries were reloaded. I had to remove the form tag.
  • Outputting HTML using .innerHtml() caused an error.

More experiments going forward

I’ll be publishing more of my PyScript experiments.

--

--

Data Science, Topic Modelling, Deep Learning, Algorithm Usability and Interpretation, Learning Analytics, Electronics — Brisbane, Australia

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Aneesha Bakharia

Data Science, Topic Modelling, Deep Learning, Algorithm Usability and Interpretation, Learning Analytics, Electronics — Brisbane, Australia