A pygame API-compatible reimplementation for running `pygame`-style code inside Jupyter notebooks (backed by ipycanvas).
Project description
ipygame
ipygame is a pygame-style API for writing small games inside Jupyter notebooks, primarily for teaching and classroom use. Instead of SDL2, it renders to an ipycanvas canvas output, so it works in environments where you do not have a desktop window (e.g. JupyterLab, hosted JupyterHub).
PacMan running with
ipygame. Credit: https://github.com/AnandSrikumar/PyPacman
The goal is API familiarity, not perfect drop-in compatibility. Many common drawing and event patterns work, but the browser and the widget stack impose limits. Audio works as well; but it's currently experimental.
Install
For local notebooks (CPython kernels), install from PyPI:
pip install ipygame
or from source:
pip install git+https://github.com/Kamuyin/ipygame.git
Quick start
import ipygame as pygame
screen = pygame.display.set_mode((420, 260))
screen.fill("midnightblue")
pygame.draw.rect(screen, "gold", (30, 30, 140, 80))
pygame.draw.circle(screen, "tomato", (280, 130), 50)
pygame.display.flip()
You might also want to temporarily register ipygame as the pygame package if you already have a codebase that uses pygame.
import ipygame
pygame.install_hook()
# Then the kernel always uses `ipygame` without the need to adjust your codebase.
Examples
The examples/ folder contains notebooks for basic drawing, input handling, and small game demos.
Documentation
Docs and API reference: https://kamuyin.github.io/ipygame
Limitations and known issues
Some pygame features are not applicable in the browser or are not implemented yet. For a high-level view of what is currently covered, check the API coverage page in the docs.
Performance can be noticeably lower than desktop pygame. Rendering happens through the browser canvas and a widget message channel, so high-FPS loops and pixel-heavy effects pay extra overhead, and there is no native SDL2 window/GPU pipeline like on the desktop.
If you run the examples in JupyterLite (Pyodide), you may see rendering work while real-time keyboard/mouse input does not. This is a limitation of the Pyodide kernel + widget message processing for long-running loops, and it is not something ipygame can reliably fix from Python alone.
Acknowledgements
ipygame is based on the work by the pygame and pygame-ce projects and aims to provide a familiar API for educational notebooks. This project is not affiliated with, endorsed by, or a replacement for pygame/pygame-ce.
License
Licensed under the GNU Lesser General Public License v2.1 (LGPL-2.1-only). See LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ipygame-1.0.0.tar.gz.
File metadata
- Download URL: ipygame-1.0.0.tar.gz
- Upload date:
- Size: 396.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
35410048e55e4c4f7312c555af0e188f3cb6face9615031c99410179e5e2c8a7
|
|
| MD5 |
c439472afc3b6eb2fc4ef2e1297cf275
|
|
| BLAKE2b-256 |
285df7dccfa2bbd144576e931745d4e55a0161d8de20f422f527ca51a08c3664
|
Provenance
The following attestation bundles were made for ipygame-1.0.0.tar.gz:
Publisher:
publish.yml on Kamuyin/ipygame
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ipygame-1.0.0.tar.gz -
Subject digest:
35410048e55e4c4f7312c555af0e188f3cb6face9615031c99410179e5e2c8a7 - Sigstore transparency entry: 1175267539
- Sigstore integration time:
-
Permalink:
Kamuyin/ipygame@3019e3e26280328947f2f7fc62d7bb066feb5f89 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/Kamuyin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3019e3e26280328947f2f7fc62d7bb066feb5f89 -
Trigger Event:
push
-
Statement type:
File details
Details for the file ipygame-1.0.0-py3-none-any.whl.
File metadata
- Download URL: ipygame-1.0.0-py3-none-any.whl
- Upload date:
- Size: 73.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3e46bbed59d67ce53c477068c8bce1993948e49514de50c23d54db99525cacec
|
|
| MD5 |
9064d4c3d3fa04fa9a848b0afd234c71
|
|
| BLAKE2b-256 |
646767ba3148e43006becab8eddffc5a1c4d8718800d4b7cf3ac9b60ed6e7254
|
Provenance
The following attestation bundles were made for ipygame-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on Kamuyin/ipygame
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ipygame-1.0.0-py3-none-any.whl -
Subject digest:
3e46bbed59d67ce53c477068c8bce1993948e49514de50c23d54db99525cacec - Sigstore transparency entry: 1175267576
- Sigstore integration time:
-
Permalink:
Kamuyin/ipygame@3019e3e26280328947f2f7fc62d7bb066feb5f89 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/Kamuyin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3019e3e26280328947f2f7fc62d7bb066feb5f89 -
Trigger Event:
push
-
Statement type: