PyScript — Going Truly Serverless
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.
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.
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.