New from Anaconda: Python in the Browser

Supporting open source and creating tools that enable people to do more with less are why I joined Anaconda almost eight years ago.

Today, at PyCon US 2022, I’m happy to unveil a new project that we’ve been working on here at Anaconda. We have high hopes that this will help Python take a serious step towards making programming and data science more accessible to everyone.

Say Hello to PyScript

PyScript is a framework that allows users to create rich Python applications in the browser using a mix of Python with standard HTML. PyScript aims to give users a first-class programming language that has consistent styling rules, is more expressive, and is easier to learn.

What is PyScript? Well, here are some of the core components:

  • Python in the browser: Enable drop-in content, external file hosting (made possible by the Pyodide project, thank you!), and application hosting without the reliance on server-side configuration

  • Python ecosystem: Run many popular packages of Python and the scientific stack (such as numpy, pandas, scikit-learn, and more)

  • Python with JavaScript: Bi-directional communication between Python and Javascript objects and namespaces

  • Environment management: Allow users to define what packages and files to include for the page code to run

  • Visual application development: Use readily available curated UI components, such as buttons, containers, text boxes, and more

  • Flexible framework: A flexible framework that can be leveraged to create and share new pluggable and extensible components directly in Python

All that to say… PyScript is just HTML, only a bit (okay, maybe a lot) more powerful, thanks to the rich and accessible ecosystem of Python libraries.

Programming for the 99%

We wanted to provide a reliable and accessible framework for creating and shipping applications to any hardware and software platform, while still having fun. In pursuing this, we did not want to create an entirely new technology stack. We wanted to start from the best options the ecosystem provides today.

Searching for the perfect platform to build on top of was hard. On one hand, we have created more elegant languages, and have made things faster, bigger, and more scalable; on the other hand, the surrounding technologies enabling those advancements are mirrored in the complexity of their underlying infrastructures.

But then, we had a voila moment.

With a little bit of flexibility, we believed that the browser would be a great platform that we could adapt to to achieve our goals of providing a reliable, accessible, and fun experience for PyScript users. The browser works everywhere (from laptops, tablets, to phones), and is secure, powerful, and stable. Making it, in our opinion, the perfect starting point for carrying out PyScript’s goals.

PyScript’s goals:

  • Offer a clean and simple API

  • Support standard HTML

  • Extend HTML to read custom components that are opinionated and reliable

  • Provide a pluggable and extensible components system

PyScript Sits on the Shoulder of Giants

There are many elements that make the browser a very solid stack, such as the advancements made with WebAssembly/WASM, Emscripten, and Pyodide. The browser makes for an excellent virtual machine, even though it is not traditionally thought of as one.

It is unfortunate that, in the last few decades, Python and powerful UI languages such as modern HTML, CSS, and JavaScript have not leveraged each other. Python didn’t have a straightforward way to build elegant UIs to easily package and deploy applications; and modern HTML, CSS and JavaScript face the challenge of their steep learning curve.

Allowing Python to leverage HTML, CSS and JavaScript conventions not only solves those two challenges, but also addresses general web application building, packaging, distribution, and deployment challenges (a huge PITA)! Overall, we hope to see the popularity and adoption of HTML, CSS, and JavaScript rise alongside Python, ultimately making the web a more friendly and hackable place for everyone.

Where is PyScript Today?

This is just the very beginning of PyScript, and our vision for PyScript goes far beyond what we can demonstrate today. While it is still unstable and limited, it does actually work!

Don’t believe me? Check out https://pyscript.net/examples/ to see it for yourself! For more information about how to start using PyScript and to check out the latest developments, please visit pyscript.net.

Let’s Build More Cool Stuff

I really like to think of PyScript as the “Minecraft of software development”: Users crafting their own worlds (applications) or new blocks and mods (components and widgets), and sharing them with the world.

This is the exciting beginning for supporting new ways of programming, building, sharing, and deploying applications. Ultimately, we should be spending our time thinking and writing applications to solve the real problems we have, not dealing with mundane, hardware-induced challenges. Let’s make programming more fun and simple.

To learn more about how PyScript works, head on over to our technical blog.

Thank You!

PyScript wouldn’t be here today without the help of some incredible people.

Big thank you to the following for your contributions to the project and helping spin:

  • Peter Wang, Kevin Goldsmith, Philipp Rudiger, Antonio Cuni, Russel Keith-Magee, Mateusz Paprocki, Princiya Sequeria, Jannis Leidel, David Mason, Michael Verhulst, and Chris Leonard

And especial thanks to the Pyodide maintainers:

  • Hood and Roman Yurchak, and all Pyodide contributors

Talk to an Expert

Talk to one of our experts to find solutions for your AI journey.

Talk to an Expert