software · Q576
pygame
Python multimedia library for code-driven games using SDL-based graphics, input and audio.
Overview
pygame is a Python library for games and multimedia applications built on SDL and related libraries. It provides image surfaces, drawing, input events, sound and optional sprite-management helpers while leaving the main loop under application control. This article covers the upstream pygame distribution, distinct from the separately maintained pygame-ce fork.[1][2][7]
Main loop and responsiveness
A pygame program normally initializes its modules, creates a display, processes events, updates application state and draws each frame. The event queue is bounded and can drop newly arriving events when full. Its documentation therefore makes regular event processing part of the application's responsibility, including when the program otherwise polls device state directly. Event operations also carry restrictions tied to the thread that initialized the display.[2][4]
Images and drawing
Surfaces represent images with a defined resolution and pixel format. Blitting copies image content onto another surface, with clipping and transparency controlling the result. A subsurface can share its parent's pixels, so modifying either can affect the same underlying image. For substantial pixel work, the documentation points to PixelArray or NumPy-backed surfarray operations instead of repeated individual pixel calls.[3]
Sprites and game objects
Sprite and Group classes are optional conveniences rather than a mandatory engine architecture. Developers supply image and rectangle attributes for basic group drawing and can use different groups for rendering and interaction. Collision helpers cover shapes such as rectangles, circles and masks. The module warns that sprites are not thread-safe, so introducing worker threads does not automatically make shared object manipulation safe.[5]
Audio behavior
The mixer loads Sound objects and plays them through a configurable pool of channels, with mixing occurring in background threads. A separate music interface streams long-running tracks instead of loading an entire sound into memory. Mixer availability depends on its SDL_mixer dependency and successful initialization. Buffer configuration can trade latency against dropout risk, so audio behavior should be evaluated with the actual distribution and hardware.[6]
Environment and documentation
The upstream package is distributed as pygame and depends on Python, SDL and several media-related libraries. The README warns that online documentation follows development and may describe features newer than an installed release. A project's supported Python version, packaged native dependencies and feature expectations should consequently be evaluated together, rather than inferred from a documentation page's availability alone.[1]
Licensing
The README identifies LGPL version 2.1 as pygame's license and explicitly permits commercial and closed-source games. Modifications to the library itself and redistribution obligations remain separate from the license chosen for game code. It also identifies bundled example programs as public domain and directs developers to the dependency notices for other incorporated components.[1]
Relationship to Community Edition
pygame and pygame-ce offer overlapping Python game-development APIs, but they are distinct distributions. CE's installation guide warns against keeping both installed together because of package conflicts. Choosing upstream pygame can cover projects that stay within the shared API, but CE-only functions need separate review before switching back. Neither the common import name nor project ancestry establishes identical behavior for every game.[2][7][8]
Capabilities & limitations
Surface-based 2D graphics
supportedSurfaces represent images and support blitting, clipping, transparency and pixel manipulation.[3]
Building code-driven 2D games and multimedia applications in Python · Windows, macOS, Linux · Version, build and integration requirements apply
1 source · check evidence
Images, blitting, clipping, pixel access and shared subsurfaces
vendor · checked 2026-10-07Application-controlled loop
supportedThe application explicitly processes events, updates behavior, draws and presents frames.[2][4]
Building code-driven 2D games and multimedia applications in Python · Windows, macOS, Linux · Version, build and integration requirements apply
2 sources · check evidence
Application-controlled game loop and module overview
vendor · checked 2026-10-07Queue capacity, per-frame handling and display-thread restrictions
vendor · checked 2026-10-07Sprite grouping and collision queries
supportedOptional Sprite and Group classes provide organization and rectangle, circle or mask collision helpers.[5]
Building code-driven 2D games and multimedia applications in Python · Windows, macOS, Linux · Version, build and integration requirements apply
1 source · check evidence
Optional Sprite/Group classes and collision helpers
vendor · checked 2026-10-07Sound effects and music
limitedThe optional SDL_mixer-backed module requires initialization and available dependencies; music has a separate streaming path.[6]
Building code-driven 2D games and multimedia applications in Python · Windows, macOS, Linux · Version, build and integration requirements apply
1 source · check evidence
Optional mixer, channels, background playback and streaming music
vendor · checked 2026-10-07Can substitute for
These are products or services this entry can replace. Check the task and limitations for each comparison.
pygame-ce for Building code-driven 2D games and multimedia applications in Python
limitedAssessment: an alternative for Python 2D projects that only need the shared pygame-style APIs. CE-specific additions are not established as available upstream, and the two distributions must not be treated as independent co-installable providers of different import namespaces.[2][7][8]
Windows, macOS, Linux · Version, build and integration requirements apply
References
- pygame README
Scope, installation, documentation versions, dependencies and licensing
vendor · retrieved 2026-10-07 - pygame documentation
Application-controlled game loop and module overview
vendor · retrieved 2026-10-07 - pygame Surface reference
Images, blitting, clipping, pixel access and shared subsurfaces
vendor · retrieved 2026-10-07 - pygame event reference
Queue capacity, per-frame handling and display-thread restrictions
vendor · retrieved 2026-10-07 - pygame sprite reference
Optional Sprite/Group classes and collision helpers
vendor · retrieved 2026-10-07 - pygame mixer reference
Optional mixer, channels, background playback and streaming music
vendor · retrieved 2026-10-07 - pygame-ce README
Separate fork and Python multimedia scope
vendor · retrieved 2026-10-07 - Installing pygame-ce
Conflicting package installation and isolated environments
vendor · retrieved 2026-10-07
Discussion & disputes
Ask about unclear claims or explain a concern with supporting sources. If you have a specific fix, suggest a correction.
No discussion yet.
Revision history
Open a revision to read an earlier version of this article.
| Revision | Timestamp | Edit summary |
|---|---|---|
| 624 | 2026-10-12 23:11:45 | /* wbeditentity-create-item:0| */ sf:c6099228-31ed-4af8-b828-a86673945a26:v1 | Adds upstream pygame, separately from pygame-ce, with explicit event-loop ownership, Surface/sprite workflows and optional audio dependencies. The CE comparison | attribution: /proposals/c6099228-31ed-4af8-b828-a86673945a26 |