Using pgame in pyscript

Hi,

do anyone use pyscript together with pygame?

Best regards Hebi

2 Likes

dear hebi

Pygame needs a lot of computing speed, right?
The trouble is that you have to increase the power of pyscript.net’s cloud server by 10 to 100 times … Maybe it will be a boring game, right?

To solve this problem,

  1. To be able to install on the local server (solved)
  2. To be able to drive powerful arithmetic units such as GPU (currently in progress, various drivers are under development)
  3. Configure a library that game developers will want to use (this is owned by the game vendor)

That’s right.

A toast for the future that is about to begin.

Regards, you.
ktsh.tanaka.2020

It’s not quite what you asked, but you may want to take a look at various links here:

They’re using wasm to get pygame working on the web

3 Likes

If you want to follow along with development take a look here: pygame for web browser · Issue #718 · pygame/pygame · GitHub

3 Likes

PyScript + Pygame is tricky — SDL backend doesn’t run natively in browsers, so you need a workaround.

Two approaches:

  1. Pygbag — packages Pygame games to WebAssembly. Works with PyScript but adds bundling complexity.

  2. Pyodide + Pygame-CE — has experimental WASM support. Cleaner but limited audio/input.

For action-heavy games like rhythm platformers (think mobile rhythm game style with tight input timing), native Android via Kivy or Buildozer outperforms browser-based Pygame every time. Browser is fine for puzzles, not for reflex games.

Yes, you can absolutely run a Pygame script in the browser using PyScript! Since PyScript runs via Pyodide, you’ll want to look into pygame-ce (Community Edition) or tools like Pygbag for the best web compatibility. It’s perfect for sharing simple 2D games directly online.

I haven’t used PyScript with Pygame yet but I worked on a browser-based AI application that runs computer vision models directly in the browser. Getting Python-related workflows to perform well on the client side definitely has its own challenges. Curious to hear if anyone has successfully used PyScript with Pygame in production.

I’ve run into the same general issue with Python in the browser. PyScript makes the workflow surprisingly convenient, but once you start using something like Pygame, the WebAssembly/browser event loop becomes the part you really have to design around.

For a production Pygame project, I’d also look at pygame-ce together with pygbag rather than assuming PyScript is the only route. Pygame-ce is actively maintained, and the pygame-web tooling specifically targets running Pygame through WebAssembly in the browser. You generally need to make the main loop async-friendly and avoid synchronous desktop-style I/O.

So I’d be interested in production examples too, but I suspect the biggest difference is whether the application was designed for the browser from the beginning rather than simply taking an existing desktop Pygame project and putting it behind PyScript.
For browser-based gaming projects, I also think it’s useful to see how real-world gaming platforms handle their web interfaces and performance. https://mostbet.net.in/ is one example that comes up in online gaming discussions, and looking at how such sites structure browser interactions can be interesting from a technical perspective. It’s another reminder that responsiveness and reliable client-side behavior matter a lot when everything runs in the browser.