r/PyScript • • Dec 12 '22

Can PyScript be used in in-browser development console?

I want to manipulate html objects after the page is rendered (for example manipulate youtube.com elements) using Python or Python-JS mixture. Is this possible?

5 Upvotes

5 comments sorted by

View all comments

Show parent comment

2

u/TheSwami Dec 13 '22

You could use JS in the dev console to tell the page to load PyScript (or Pyodide), then use pyscript.runtime.run() to execute your python in the console:

script = document.createElement('script')
script.src = "https://pyscript.net/releases/2022.12.1/pyscript.js"
document.head.appendChild(script)
(wait for load)
pyscript.runtime.run('print("Hello from Python!")')

1

u/CookiesDeathCookies Dec 13 '22

Wow, so it's actually possible to do what I want. Many thanks!

Is it possible to do this with other languages? My guess that it's possible because of wasm. If there's a project for this language like PyScript for Python.

2

u/TheSwami Dec 13 '22

Agreed, it's the WASM runtime as well as a compatible JavaScript interface layer that really make this feasible.