5 ms·
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
by mg 2y ago
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.
- pansa2 2y ago> transpiles them from Python to JavaScript 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.
- deleted 2y ago[deleted]
- deisteve 2y agodoes this mean we can install FastAPI in the browser?
- bouncing 2y agoI mean, maybe, but you'd have trouble with sandboxing when you try to open a socket.
- deisteve 2y agohow would i go about doing that? open up a socket via webrtc to the internet and translate incoming webrtc calls to HTTP for fastapi
- nine_k 2y agoWhat would be the point? 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.
- maartenbreddels 2y agoYes, with pycafe that is possible: https://py.cafe/snippet/asgi/v1#c=H4sIABN3wGYAA41UTW_bMAz9K4Z2aYFEs52vxoCBfWBDdxt2WA91D4pFx8IcSZOYtkaQ_z4yTtYVa5FGp0c-8j3SUnaidhpEIZrgNkmjIipvErPxLmDyleDH798qq7xPyhO8uKwsnw8UlWvAi0q8rwQFVextnWhokuAcXlwWlU3oFwC3wSa7SmwgRrWGShRJJa6h61xy40KnK7EXIxHg99YE2IDFSIbISegAESp7tEUc7D2bVXHNiAz8NPAgikZ1EUYCtMEvVq064mDYUsT32DpLFb532mgY36cyn8uMijvVuy2KYifuIUTDrJxMkPMfjlruTlqB0EjUrel0ACLd_s2gWkVASj4Yja0oslk6EhtjbwY4GdA1mHVLOgyN5k2bDj5R1wjhs7OojIXwigJTx6uBSxSvuK8Q-7v96H8Xr1h8quPv5XvxvPYp_e_-JT7ic5k3rOH86MdRzo19mvjlOdtj12wxe4smQqCw6s6Jnnisymc_OqyfruLtHd0WV_9iyF1oQcR_l7QqtkUyuZqv6umknsyXq8Vsms1gmYPOm6Weq6VK08pGa5rGuLLM5ERm9E5sz2gqp5Kzp3telqmcXMm8sm2WMcgO-RbR1y5QOpOpnA2BR87nC84fH8ehIMu5v--9ohtt12VJetzQaKsYLCpbQ0DTED1P86nMOUsLIPIYHmkyfgiRvWWkxlatQ4Wgx7wlSqRyznHfa2XR1NRGHlzQp9l6dK4jznwpZ4OPgTQe7JO3Kw47TzKx43no0B_JEaTcR-z_APpsUxySBAAA https://py.cafe/snippet/asgi/v1#c=H4sIABN3wGYAA41UTW_bMAz9K4...
- rty32 2y agoWithout actually reading the documentation or source code -- I guess "js" package is just an API that somehow maps to the real "window" object and calls those DOM methods via some sort of Proxy object.
- mg 2y agoProbably. It is part of Pyodide, not something this PyScript project adds: https://pyodide.org/en/stable/usage/quickstart.html#accessing-javascript-scope-from-python https://pyodide.org/en/stable/usage/quickstart.html#accessin...
- dr_kiszonka 2y agoI found some info about the terminal here: https://docs.pyscript.net/2024.8.2/user-guide/terminal/ https://docs.pyscript.net/2024.8.2/user-guide/terminal/ (I was hoping to be able to run Python in the browser's console.)
- sjamaan 2y ago> And the title says "platform". So I'm still confused. 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.