Home > Mobile >  How to run python code directly on a webpage
How to run python code directly on a webpage

Time:02-17

My problem is as follows: I have written a python code, and I need to run it on a web page.Basically I need that whatever is on the console should be displayed as it is.

I have no experience in web development and similar libraries, and I need to get this done in a short time. Kindly tell how should I proceed?

Note: I might be plotting some graphs also. It would be great if they could be displayed all at once(sequentially) on the website

CodePudding user response:

You Can't execute Python-Code directly inside a webbrowser - however, you could for instance create a basic IDE in HTML & JS, send code written by a user on the page to a Server, which would then run the code and send the results back to the client-page.

Unfortunately, such a project is quite ambitious and complicated, especially when Security & Stability are of mayor concern, as executing client-code is a very dangerous measure indeed, and requires expertise in Virtualization Techniques & Software.

Another Method could be to use a public API, which allows you to run Python code and fetch the results back. The procedure would be exactly the same as with the previous idea in terms of creating the web-client, but the heavy-lifting - which is actually executing the Python-code, would be taken care of for you.

As you can see, there is no concrete answer to this question, only suggestions.

A few useful links below:

https://docs.docker.com/

https://appdividend.com/2022/01/18/best-python-online-ide/

https://www.makeuseof.com/tag/programmer-browser-ides/

https://www.youtube.com/watch?v=og9Gaj1Hzag

How do I execute a string containing Python code in Python?

CodePudding user response:

https://brython.info/ https://skulpt.org/ https://pyodide.org/en/stable/

There are multiple python implementation on browser, some are webassemble some are javascript.

Is it a good idea to run python on browser as a replacement for javascript in 2022? No it is not, learn javascript. No in-browser python implementation can race with javascript as of today and most probably ever.

  • Related