274 points · by xiaodai · 2y ago · 145 comments
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).
On iPad Pro 13" from fall 2023, over NYC area broadband and WiFi, it takes about 8 seconds from clicking your link for the spinner (which seems to hang from seconds 4 - 8) to clear and the filters to become active.
Not sure how long bootstrapping enough Python into Safari on an iPad to run a Panel app would take, but I certainly imagined more than 8 seconds. (Shift refresh takes ~6.)
I wonder what your bottleneck was? It was about 20 seconds for me on domestic broadband.
> Many businesses I work with use Tableau free versions, and just manually update the data
Why not just use e.g React/ Angular?
Or is it a question of needing python for the data analytics, and for server cost reasons not wanting it to be run on the server side?
There are some cases in which I do want python numerical libraries though. Say I wanted to do a forecast ARIMA model based on arbitrary combined inputs for the graphs, or do different types of spatial clustering of the geographic data. Those would be cases pyscript would make sense.
The public dashboards yes IMO easier to not have to worry about server.
I wish we get over with the loading hickups soon. Do you know if there is any work going on to make it start faster/smaller/less janky?
I imagine there's a ton of preprocessing that could be, well, preprocessed.
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.
There are projects that do that, but it looks like PyScript instead runs Python code directly. It uses a Python interpreter compiled to WebAssembly - either CPython (from Pyodide) or MicroPython.
You can't have a listening socket anyway. And if the browser has to imitate the connection, there are numerous less oblique ways than running fastAPI.
I hate it when people say "platform" or use other vague/ill defined terms. Just say it's a JS implementation of Python that evaluates code in script tags for python, or some such.
https://pyodide.org/en/stable/usage/quickstart.html#accessin...
(I was hoping to be able to run Python in the browser's console.)
https://pyscript.net/tech-preview/micropython/about.html
In fact the main PyScript site uses MicroPython now, I see in the dev console (micropython.mjs and micropython.wasm).
PyScript can use Pyodide or MicroPython. MicroPython is actually quite small.
On top of the runtime, PyScript gives you some pleasantries and a lot of quality-of-life improvements for actually using Python for web programming, not just being able to run Python code.
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/
You can't run TS in the browser unless you jump through the same hoops that PyScript is.
Is there something which can do this? and with full power of python also accessible to the host?
https://pyodide.org/en/stable/usage/packages-in-pyodide.html
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.
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...
Kernels are compiled to wasm and can therefore run in the browser.
Try it out at: https://jupyterlite.readthedocs.io/en/stable/_static/lab/ind...
Its easy to create your own deployments, there is a template repo for that https://github.com/jupyterlite/demo
Had a quick look, this seems quite cool!
Is there alternative output is the WASM is not run? It would be good if it defaulted to a pre-run static output, otherwise users could be left with nothing?
Huh? I thought Python didn't have TCO anyway. Guido had a whole blog post about why it supposedly doesn't belong in Python: https://neopythonic.blogspot.com/2009/04/tail-recursion-elim...
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.
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/
Brendan Eich originally wanted to use Scheme. There are some Scheme in Javascript implementations:
https://n8henrie.com/2023/06/write-a-firefox-extension-in-py...
This also uses pyodide, but supports more frameworks out of the box.
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...
The whole thing runs via PyScript/WASM, and lives locally inside the Excel spreadsheet. https://www.anaconda.com/blog/introducing-anaconda-code-add-...
This is, I assume, Visual Studio for Windows. Have you tried it at all in VS Code or is that a non-starter?
Yes, Python is among the slower interpreted languages out there, but still. The debate between fast execution and programmer productivity is not a new one. Given Python's popularity, I'd say it's settled.
Yes, interpreted Python will always be slower than JIT-compiled JavaScript.
PyPy.js [0] is a JIT compiler for Python that runs in the browser - its performance could be similar to JS but its development is currently “sleeping”.
The commercial licenses for the products and commercial repository is what supports all of this OSS development work.