August 16th, 2024

PyScript: An open source platform for Python in the browser

PyScript is an open-source platform that allows users to run Python in web browsers, enabling easy app development, scalability, security, and accessibility through URL sharing, democratizing programming for a wider audience.

Read original articleLink Icon
CuriosityFrustrationSkepticism
PyScript: An open source platform for Python in the browser

PyScript is an open-source platform that allows users to run Python directly in web browsers, merging the capabilities of the web with the popular programming language. It aims to empower users by providing a familiar and accessible computing environment. PyScript is designed to be easy to use, requiring no complex installation processes, and allows developers to create applications using Python, which is known for its simplicity and expressiveness. The platform is scalable, as applications run in the user's browser without the need for costly infrastructure. Additionally, PyScript applications can be easily shared via URLs, making them universally accessible. The platform emphasizes security by operating within the browser, which is considered a robust computing environment. Overall, PyScript represents a significant step in making Python more accessible and functional for web development.

- PyScript enables running Python in web browsers without complex installations.

- It combines the strengths of Python and web technologies for app development.

- Applications created with PyScript are easily shareable via URLs.

- The platform is scalable and secure, leveraging the browser's capabilities.

- PyScript aims to democratize programming by making it accessible to a wider audience.

AI: What people are saying
The comments on PyScript reveal a mix of experiences and opinions regarding its functionality and usability.
  • Users share practical use cases, such as creating dashboards and applications, highlighting its potential for web development.
  • Some express confusion about its purpose and functionality, comparing it to other tools like Pyodide and Brython.
  • Concerns are raised about the complexity and performance, with some noting slow execution times and challenges with dependencies.
  • There are discussions about the implications for developers, including potential maintenance issues and the impact on coding practices.
  • Several users suggest alternatives or express skepticism about PyScript's effectiveness compared to established frameworks like React.
Link Icon 28 comments
By @apwheele - 2 months
For folks interested in seeing a usecase, I have a panel dashboard of Dallas crime statistics at:

https://crimede-coder.com/graphs/Dallas_Dashboard

Startup takes around a minute (which includes installing various python libraries + loading an external 5mb dataset). But once up and running it is quite responsive. (And works fine on my iphone.)

Many businesses I work with use Tableau free versions, and just manually update the data (since the free doesn't allow direct connections to a datastore). This is a free alternative (I use github actions to build a zipped up csv file that is pulled into the environment).

By @mg - 2 months
The homepage left me confused, and also after reading the documentation, I'm not sure what this is.

I tinkered a bit to try it myself.

Turns out you can throw this into your website and it will display "Hello World":

    <script type="module" src="https://pyscript.net/releases/2024.8.2/core.js"></script>
    <script type="py">
        import js
        js.document.querySelector("body").innerText = "Hello World"
    </script>
So it seems to be a script that looks for scripts of type "py" and transpiles them from Python to JavaScript via Pyodide?

On the other hand, the demo on the homepage is a repl. And the title says "platform". So I'm still confused.

By @Loeffelmann - 2 months
How is this different from pyodide[0]?

[0]: https://pyodide.org/en/stable/

By @pitah1 - 2 months
I recently went down the rabbit hole of using PyScript for running a Python CLI app in the browser.

It felt hacky the whole time, especially when dependencies were involved. I had to create wrapper classes to work around Pydantic 2.x not being available to use. I tried to put all logic into the Python files but found some things missing that I had to put in JavaScript.

I think it could be good in use cases where you want some simple UI with custom UI logic on top of your Python code but maybe Streamlit or Gradio could be more suitable.

GitHub repo: https://github.com/data-catering/data-contract-playground

Website: https://data-catering.github.io/data-contract-playground/

By @v3ss0n - 2 months
I can't find any real world use case there. If you want to run ML Models you can build them to Onnx https://onnxruntime.ai/docs/tutorials/web/ . Will this efficient to build browser based app in place of JS/TS ?
By @deknos - 2 months
What i would like, if i could write scripts in firefox, which act the browser, like doing the evaluation at any stage i like. At GET the page, after ALL GETs. After javascript evaluation or before.

Is there something which can do this? and with full power of python also accessible to the host?

By @zygentoma - 2 months
Isn't this the same concept as brython? (BRowser pYTHON)

https://brython.info/

https://github.com/brython-dev/brython

By @bouncing - 2 months
If I may toot my own horn, I wrote a somewhat more opinionated, reactive, frontend framework using PyScript. It's inspired by Vue.js, a bit: https://puepy.dev
By @amanzi - 2 months
I used this to create a Markdown renderer a while back. You can see the very simple source code here: https://pyscript.com/@stuartmaxwell/markdown-previewer-v2/la...

The app won't run well on mobile but should be fine on desktop.

I used this code in a blog application I was writing in Django.

By @raybb - 2 months
The big limitation that's very annoying with any WASM setup is that at the end of the day you still can't call many APIs or scrape sites because of CORS. Ofcourse, CORS is important to avoid XSS and the like but I wish there was a way to deal with this other than setting up a proxy to strip CORS, which then leaves you with a non residential IP that's more likely to get blocked.
By @bArray - 2 months
I've been looking for something like this, but I'm still unsure it quite hits the spot. I think that this would be very interesting if it allows a person to run a blog like a Jupyter notebook.

I have a lightweight hack [1] that runs Python in markdown documents and can output basic images/graphs - which is embedded into static pages. The point was being able to write an article that somebody else could see the code behind it and test themselves, e.g. [2]. One of the browsers I test in is Netsurf with JS disabled. Unfortunately it doesn't look great in Lynx.

[1] https://gitlab.com/danbarry16/pandoc-highlight-filter

[2] https://coffeespace.org.uk/projects/langtons-ant-universe.ht...

By @jedberg - 2 months
First thing I tried was a small lambda function and it worked! Then I tried some Fibonacci with tail recursion and surprisingly that worked too. I'm impressed, because often when people reimplement the Python interpreter they get those wrong.
By @bdcravens - 2 months
Reminds me of my first "tech" job (computer store/ISP/web dev shop, circa 1998) where the owner wrote some VBScript for the browser and wondered why it didn't work in Netscape.
By @a10sshg - 2 months
This is from Anaconda and built on Pyodide:

PyScript is currently built on Pyodide, which is a “port of CPython to WebAssembly/Emscripten.” PyScript supports writing and running Python code in a browser.

Like conda I find the whole thing very confusing and slow, but I suppose it will be marketed to academics as "the thing to do web development with". It will also be soft-abandoned.

Just use Javascript, PHP or Scala like lichess.org, which is a professional website.

By @nickpsecurity - 2 months
For those exploring, here was one of the best “Python in the browser” projects I found:

https://brython.info/

By @grej - 2 months
Also check out pyscript.com, to create and host PyScript apps.
By @laffra - 2 months
Also, check out PySheets (https://pysheets.app), which leverages PyScript to run Python logic in a spreadsheet UI, which is written entirely in Python. The PySheets UI uses LTK (https://github.com/pyscript/ltk), a fully client-side UI rendering library for PyScript.
By @maartenbreddels - 2 months
Also check out https://py.cafe/ (I work on this project)

It supports streamlit, dash, virzo and solara. Frameworks like shiny, gradio and panel are planned (maybe even fasthtml).

It's also really nice to integrate this into your documentation: https://mkdocs.py.cafe/

By @agumonkey - 2 months
What other language would people choose in a browser? Lua ?
By @n8henrie - 2 months
I tried to write a POC Firefox extension in pyscript but ended up having to fall back to pyodide. Was a fun experiment anyway.

https://n8henrie.com/2023/06/write-a-firefox-extension-in-py...

By @bityard - 2 months
Why does it require signing in just to try it out? Someone else below mentioned that it's just adding a <script> tag to your HTML.
By @Falimonda - 2 months
Does something built off this or Pyodide exist that's effectively a replacement to using React?
By @jerpint - 2 months
I wonder if this could be combined with fastHTML to have a full python html rendered client side
By @IshKebab - 2 months
The examples were about as slow as I imagined they would be. 20 seconds to draw a simple graph.
By @bilsbie - 2 months
How’s it work? Webassembly? Webile?
By @SillyUsername - 2 months
Someone just invented a whole new level of hell for devs who maintain code.

First it was untrained consultants and VB or Delphi (Pascal)

Then came the JS monkeys mixing up plain JS with jQuery and SQL injections.

Now it's time for data scientists and pi/sketch users to feel the pain of an uncharted domain...

By @bschwindHN - 2 months
Our phones are getting faster every year, we must find a way to slow things down even more.
By @apples2apples - 2 months
Careful Anaconda will change the license on you and then sue...