2

I have created a really cool Python program that I want all of my friends to try out. I really want to put the running code onto a website so people can try it all around the world. Is it possible to run Python code on a HTML page? If so, how?

2
  • You can't run Python in a browser without Python being installed on the user's system. Commented Aug 30, 2014 at 5:59
  • 1
    @MattDMo -- I would beg to differ, though I would agree that strictly speaking the browser itself cannot directly interpret python code unless it is installed on the local machine. However, there are several options for sharing runnable python code online. Commented Aug 30, 2014 at 6:13

2 Answers 2

4

In answer to your question: Yes, this is possible.

If you merely want to share your code with your friends, and allow them to try it out (even without them having Python installed), in browser, then there are a number of tools that you can use.

For example, with https://trinket.io/ , you can embed a snippet of python code in an HTML webpage or share it via a link.

Update:

Another alternative online python site is http://repl.it/. Repl.it has compiled the CPython interpreter into Javascript, using an LLVM -> Javascript compiler. It is opensource, so you could even self-host if you wanted. Caveat: Some of the libraries still have bugs in them.

Sign up to request clarification or add additional context in comments.

2 Comments

This is an interesting solution. As you seems to know that product, could you elaborate a little bit more ? Does it really run in the browser, or is Python code somehow send to a server for evaluation ? Is it free/opensource ? Does that support Python 2, Python 3, or both ?
@SylvainLeroux I've only used this service a few times, but I believe that the code is sent to the server for evaluation. It definitely supports Python 2.x, not sure on Python 3. I don't think it is opensource, although it is free (costwise). For a one off "cool script" it will probably suffice.
3

The simple pedestrian solution is to create a WSGI wrapper. You can configure your web server to accept input through a form (typically) and feed that to your Python program as input, then display the program's output as the response to the form submission. Thus your program runs on the server -- which needs to have the required services and resources -- but the user interaction happens simply using the client's web browser.

There are more-complex interaction models but this is how the entire web 1.0 was set up and is quick and easy to get going. (The spec back then was the similar platform-independent CGI API.)

1 Comment

It's 2014 - WSGI is much preferred (and has been for donkey's years now) over CGI for Python.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.