Skip to main content

A pygame API-compatible reimplementation for running `pygame`-style code inside Jupyter notebooks (backed by ipycanvas).

Project description

ipygame

Binder

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).

Snake demo running in a notebook

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.

Install

For local notebooks (CPython kernels), install from this repository:

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()

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.

Audio is work in progress.

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ipygame-0.1.0.tar.gz (371.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ipygame-0.1.0-py3-none-any.whl (68.0 kB view details)

Uploaded Python 3

File details

Details for the file ipygame-0.1.0.tar.gz.

File metadata

  • Download URL: ipygame-0.1.0.tar.gz
  • Upload date:
  • Size: 371.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ipygame-0.1.0.tar.gz
Algorithm Hash digest
SHA256 65976215359b71f8fc39cd1e4da76595da9542494c69f40b3f9cc2d974877526
MD5 e34d1499b18330efb1e82ef3cd7ecddf
BLAKE2b-256 6dd09bf255f6a27234d5497ba6ef6866ac6b55442fc1dc7647cef1574711ae10

See more details on using hashes here.

Provenance

The following attestation bundles were made for ipygame-0.1.0.tar.gz:

Publisher: publish.yml on Kamuyin/ipygame

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ipygame-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ipygame-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 68.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ipygame-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 38f3aead34843f801fdcc94e7ece5138c5a3cced1f620add26c569dafd5972bd
MD5 56dae623412d6a674aa8355fac886979
BLAKE2b-256 0f30b966c82e9c01ed986cdf60061f2cc51af3696df658f1c22299975e06b90f

See more details on using hashes here.

Provenance

The following attestation bundles were made for ipygame-0.1.0-py3-none-any.whl:

Publisher: publish.yml on Kamuyin/ipygame

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page