OPGFM is a starter kit for building small two-player turn-based online games with Pyxel.
It uses PeerJS (WebRTC) so games run peer-to-peer in the browser — no game server to host, no accounts, no cost. You copy a small template into your game, implement three methods, and your Pyxel Web export becomes an online game.
Japanese README: README.ja.md
git clone https://github.com/harukaappscreate/opgfm.git
cd opgfm
python3 -m venv .venv # Windows: py -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txt
python tools/build_tic_tac_toe_web.py
cd build/tic_tac_toe_web
python -m http.server 8000Open http://localhost:8000/ in two browser tabs:
- First tab: press
O(online lobby), thenHto create a room. Note the room number. - Second tab: press
O, thenJto join, and enter the room number.
When both tabs are connected, the match starts. Details: Tic-Tac-Toe online starter.
The sample's online lobby: a room has been created serverlessly and is waiting for the second player.
Online play runs in the browser (Pyxel Web / Pyodide). Python code talks to a thin JavaScript bridge, which talks to PeerJS. Synchronization is host-authoritative: the guest sends a pending_move, the host validates it and publishes the full game_state.
guest move
-> pending_move
-> host validates (apply_move)
-> host publishes game_state (serialize)
-> guest applies it (apply_state)
Your game logic needs to expose three small methods:
serialize() # return the current game state as a dict
apply_state() # apply a received state dict
apply_move() # validate and apply one player moveOPGFM provides the networking glue around that shape:
from multiplayer import MultiplayerManager, TurnBasedHostSync
self.multi = MultiplayerManager()
self.sync = TurnBasedHostSync(self.multi, self.logic)
self.sync.update() # every frame
self.sync.send_move({"index": index, "player": my_mark}) # on player inputSee How OPGFM connects to an existing Pyxel game.
The canonical starter files live in template/:
template/
multiplayer.py # MultiplayerManager + TurnBasedHostSync
peerjs_bridge.js # thin PeerJS bridge for Pyxel Web exports
index.html # reference HTML wiring
online_config.json # starter settings
INTEGRATION_STEPS.md # step-by-step integration guide
PeerJS itself is not vendored. Browser builds reference a fixed CDN version:
<script src="https://cdn.jsdelivr.net/npm/peerjs@1.5.5/dist/peerjs.min.js"></script>The normal Python run is for checking the title, lobby UI, board, and solo play. Online play only works in a browser build.
python examples/tic_tac_toe/main.pyA Pyxel app that visualizes the online game flow (lobby, roles, turns, sync, disconnect, rematch) and copies the starter template into generated/:
python app/main.pyDesigned for two-player, turn-based games (board games, card games). Not designed for realtime action synchronization or 3+ players.
Known limitation: the free public PeerJS signaling server can occasionally fail to connect. Reloading the page and retrying usually resolves it.
Ultimate Tic-Tac-Toe is a published Pyxel game built on the same networking approach (host-authoritative sync over a PeerJS bridge). You can play it online in your browser right now.
Ultimate Tic-Tac-Toe: an online match with turn timer and emotes, running on this architecture.
- English docs
- Tic-Tac-Toe online starter
- How OPGFM connects to an existing Pyxel game
- Japanese docs
- Third-party notices
Created by haruka_apps.
MIT License. See LICENSE.

