PyScript is a framework, built with Pyodide, allowing you to run Python code in a web client.
Its still in its infancy, but the dev team has recently released a beta version.
Although it’s still in beta, PyScript already comes with some impressive features worth trying out.
While the latter option has some small benefits, linking to the CDN is easier.
Write Python Directly Inside HTML
Your Python code sits inside a custompy-scripttag within a document’s body.
The PyScript JavaScript file will then interpret its contents using Python.
you might specify an HTML element, such as a div, for PyScript to write output to.
Here’s an example layout:
Remember that indentation is significant in your Python code.
You’ll need to be careful to indent correctly to avoida Python IndentationError.
All dependencies sit inside apy-envtag within the HTML head section:
4.
This makes it easy to write cleaner and readable code.
However, you’ll have to point thepy-envtag to your local module paths.
Similarly, you’ll list every local file you want to use in your Python code.
Render Visualizations Directly to the DOM
Sharing visualizations and dashboards can be a tricky task.
PyScript lets you display your Python storyboards and visualizations directly inside the net surf tool without using server-based solutions.
you’re free to even write an Excel sheet into the DOM as HTML.
And this is one of the reasons JavaScript stays ahead of it for web development.
PyScript’s introduction might change this if it can achieve JavaScript’s level of functionality.
However, keep in mind that some features might break, as PyScript is still an experimental framework.