Pyglet on Browsers

Well, I was wondering it it would be possible to create some kind of brower plugin for Pyglet. It seems that Python had once some kind of sandbox similar to the Java VM, but due to that sandbox not being really secure, the project was abandoned.

Recently, I found Jython. I had not paid attention to all those different Python flavors, and this one surprised me. It opens up the possibility of creating applets using Python... so... maybe, some day, Pyglet could be supported too!

What for? Well, there are many RIA platforms out there these days: Flash & Flex, JavaFX, Silverlight... why not something python-based? Certainly, Python is more friendly than ActionScript, more compact than Java and... well, it doesn't come from Microsoft ;)

What do you think about this? Would you like being able to create browser games with Python? :)

I'll ask this in the pyglet mailing list too.

(log in to comment)

Comments

you would definitely get me won over to using pyglet for most my projects ;)
I would love it :)
Pyglet + Squirtle in web browsers = win. Do it.
I once asked this question two years ago, but for pygame (skip the main post, question is on the comments, and remember it's probably outdated). I remember seeing some effort last year to convert python code to Flash called flex-pypy (see example - it was once featured on pygame.org, but I can't find the news), but unfortunately it hasn't been updated for a long time.

I've never thought about it for pyglet, but I assume the problems are the similar. If making it work for pyglet is any easier, I would like to know more about it. That's something I've wanted to see for quite some time. It would definitely be awesome if I could play pygame/pyglet games on a browser. But I think it might be a hard task.

I think getting these Python games to run in the browser would be fantastic. I'm a big fan of the Flash platform, and it's sad that flex-pypy never made it any further than it did.

However, I think there's a better option on the table right now, and that's Alchemy. Basically, it lets you compile C / C++ source to bytecode which is run by the Flash runtime -- pretty neat stuff, and so far I've seen Doom and Quake compiles to Flash. I've heard (but not seen) that people have also compiled Python with Alchemy, but I've not seen a binary for this. If we could compile Python with a few of its dependencies, it seems like we could have a pretty cool portable Pygame / Pyglet way of running these Python games in the browser.

But if Alchemy compiles C/C++ to bytecode... then the Python interpreter can be recompiled too! Oh, that's whay you said. Sorry, I was excited :D

Yes, there are some references around about someone having compiled a Python interpreter, but nothing solid. But it's probably just a matter of time, if they already have Quake working. I might try that myself.

I know it is just plain easier saying "ok, you want to play? then download my excutable file and play", but I guess that some people may feel uneasy about downloading and executing software.

Users should feel uneasy about downloading and executing untrusted software, even if it executes inside a plugin, unless the plugin takes care to do this in a "sandbox", and that sandbox gets a reputation for safety. And doing that right (without removing expressive power and graphics acceleration) is very hard. You can't just expose the OpenGL API directly -- it's possible to hang entire machines by accident when OpenGL or GLSL is malformed, and it's also easy to steal data. (At least on some machines, if you get a traceback before you clear the OpenGL framebuffer, you see a perhaps-scrambled version of a previous framebuffer from some terminated program, or part of the user's desktop. I don't want untrusted code taking screenshots of my desktop!)

So for the plugin environment to be more attractive to a well-informed user than "just download my program", it either has to be more secure (an unsolved problem if you don't want to trade away expressive power and speed), or much easier for the user (which probably means they already have the plugin, e.g. you use JNLP or Flash).

If you assume the user does trust the developer of each game, and you just want to pursue the plugin-version-of-pyglet idea so you can make the download more convenient, make it not redundantly download dependencies, etc, that might be possible, but it's certainly still a big project. (And one which is already being attempted by things like JNLP, 0install, python easy-install, etc.) And running in a browser is full of limitations and doesn't really have any compensating advantages in this case. That is, if you do solve that problem, you might as well just distribute the solution (the "more convenient system for downloading and running pyglet-based games") as a non-browser-related executable.

@Woodwolf: Neat! Are you thinking of trying this out?
@myself: Oops, I got a bit carried away there at the end... for games, the limitations of browsers are not too bad. So *if* security is not an issue, then yes, running in a plugin could add a lot of convenience.