Introducing PyScript: Run Python Directly in the Browser
PyScript, a new framework from Anaconda, enables developers to embed and run Python code directly in standard HTML pages, offering first‑class Python support in the browser, seamless integration with JavaScript, package management, and UI components, all built on the Pyodide WebAssembly engine.
Anaconda, the well‑known Python distribution, has announced PyScript, a framework that allows Python code to run directly in the browser by embedding it in standard HTML.
PyScript provides developers with the ability to write Python inside HTML, call JavaScript libraries from Python, and build full‑featured Python web applications, aiming to treat Python as a first‑class language with consistent styling and expressive syntax.
PyScript example code:
<code><py-script>Hello World</py-script></code> <code><py-script src="/my_own_file.py"></py-script></code> <code><py-env>
- bokeh
- numpy
- paths:
- /utils.py
</py-env></code>Core features of PyScript include:
Python in the browser: drop‑in content, external file hosting based on the Pyodide project, and no server‑side configuration required.
Python ecosystem: access to popular packages such as numpy, pandas, scikit‑learn, etc.
Python with JavaScript: two‑way communication between Python and JavaScript objects/namespaces.
Environment management: developers can specify which packages and files to include.
Visual application development: ready‑made UI components like buttons, containers, and text boxes.
Flexible framework: ability to create and share pluggable, extensible components directly in Python.
PyScript goals:
Provide a clean and simple API.
Support standard HTML.
Extend HTML to read stable, reliable custom components.
Offer a pluggable, extensible component system.
PyScript is built on Pyodide, which compiles CPython 3.8 to WebAssembly, allowing any PyPI package to be installed and exposing Python functions to JavaScript as well as the browser DOM to Python.
For more details on how PyScript works, see the engineering blog at https://engineering.anaconda.com/2022/04/welcome-pyscript.html .
PyScript is currently in alpha testing. Download and installation information can be found at https://pyscript.net/ .
Python Programming Learning Circle
A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.