PyScript - Python in the Browser
Last year we heard about the PyScript project as a new framework for Python users. Peter Wang, CEO of Anaconda company, presented the alpha version of this project at the PyCon conference in 2022. The motto he highlighted in his speech was “The next 100 million Pythonistas – or programming for everyone”.
While we keep an eye on the continuous upgrades since it was first presented, let’s talk about basic information and the advantages this framework brings.
How was the PyScript project invented?
The most common software developers’ perception of Python is that it’s an easy-to-learn programming language. That’s why it is often one of the top few most popular languages according to StackOverflow research.
Python scientific tools were the basis of the idea. Peter Wang and his colleague Travis Oliphant wanted to improve the data analysing and business calculations level, especially the big data.
The key advantages they saw in this project are:
- Designed for readability (“Fits in your head”)
- Easy to learn
- Rich library ecosystem
- Does many things with modest effort
- Very popular
Basic PyScript components
PyScript is a framework invented to provide users with an opportunity to create Python applications directly in the browser. We can write the code directly in an HTML interface thanks to Pyodide, Wasm, and other modern web technologies. These are the six basic components:
- Python in the browser – allows drop-in content, hosting applications without configuration servers
- Python ecosystem – usage of various popular scientific tools such as Numpy, Pandas, Sciki-learn, etc.
- Environment management – we can define which packages and files to include in running page code
- Visual application development – ease to use of UI components, such as Buttons, Containers, Text boxes, etc.
- Flexible framework – can be used for creating and sharing new components that can be included or excluded directly in Python
Elements of PyScript
With Py-config we can configure metadata and define dependencies needed for PyScript applications. Configuration is possible in TOML and JSON formats and we should place it within the <body> tag.
Read Eval Print Loop is an interactive Python framework that runs multiple code lines. If we print any of the REPL elements – the output will be shown at the py-terminal.
Allows running Python scripts whether in code or in a specific folder imported by src attributes.
This is one of the core plug-ins, and it’s active by default. It is used for printing across stdout and stderr and for listing export data on the py-terminal page.